cordova-plugin-inappbrowserxwalk icon indicating copy to clipboard operation
cordova-plugin-inappbrowserxwalk copied to clipboard

Exit event not firing if hardware back button is used.

Open aksharpatel47 opened this issue 10 years ago • 9 comments

Exit event fires when the close button is used but not when back button is used to exit the browser.

aksharpatel47 avatar Sep 25 '15 14:09 aksharpatel47

You mean Hardware back button? Am 25.09.2015 16:28 schrieb "Akshar Patel" [email protected]:

Exit event fires when the close button is used but not when back button is used to exit the browser.

— Reply to this email directly or view it on GitHub https://github.com/Shoety/cordova-plugin-inappbrowserxwalk/issues/11.

ClaasBrueggemann avatar Sep 25 '15 14:09 ClaasBrueggemann

Yes @ClaasBrueggemann.

aksharpatel47 avatar Sep 25 '15 14:09 aksharpatel47

pls how do i remove the close button from the browser and also prevent users from copying my content.. because i noticed that when the user try to copy the content, another search option shows which feels awkward.. please help. thank you

Gabynet01 avatar Nov 30 '15 23:11 Gabynet01

+1 "Hardware back button"

dhoomm avatar Jan 03 '16 09:01 dhoomm

+1 "Hardware back button"

CiteGestion avatar Apr 06 '16 07:04 CiteGestion

This is a pretty serious issue. Users can use the hardware back button, which hides the browser, but does not exit. There is no notification that the browser is no longer visible. I'd help if I better understood Android internals...but that's why I use cordova ;-)

hobzcalvin avatar Jul 08 '16 23:07 hobzcalvin

After some research and experimentation, it seems that preventing the hardware back button from hiding the browser is as simple as adding this code to BrowserDialog.java inside class BrowserDialog:

@Override
public void onBackPressed() {
    return;
}

This still allows use of the back button to move backwards in the browser's history, but once the earliest URL is reached, it does nothing. I'm not sure if I should create a pull request as this probably wants a setting or something, but adding this code to our fork of the plugin seems to work.

hobzcalvin avatar Jul 08 '16 23:07 hobzcalvin

I fixed this by adding the following code to the InAppBrowserXwalk.java file:

dialog = new BrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
                dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", "exit");
                            PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
                            result.setKeepCallback(true);
                            callbackContext.sendPluginResult(result);
                        } catch (JSONException ex) {}
                    }
                });

This way the exit event is fired when pressing the hardware back button and you can close the app in javascript if you like.

maartenvandillen avatar Jan 20 '17 13:01 maartenvandillen

Duplicate of #23 which actually fixed in last version

andreyliventsev avatar Jul 26 '18 09:07 andreyliventsev