Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent closing InAppBrowser - Cordova

I have an simple app that onDeviceReady starts the InAppBrowser and shows a website. Then The InappBrowser will be closed when a specific event occurs.

As you may know, on Android platform pressing "back button" closes the InAppBrowser which I want to be prevented. I want to InAppBrowser be shown to user until that event occurs and user be unable to close the InAppBrowser.

Be noted that I am not talking about hardwareback options. hardwareback is a useful option which lets user goes back in history of his/her navigation by pressing "back button" but at the first page (when there is nothing left in history), it closes InAppBrowser while I want InAppBrowser still remains open.

like image 711
FatDog47 Avatar asked Nov 01 '22 07:11

FatDog47


1 Answers

In the latest InAppBrowser versions you still have to change the onBackPressed function in the JAVA code of InAppBrowserDialog.java plugin code:

public void onBackPressed () {
    if (this.inAppBrowser == null) {
        this.dismiss();
    } else {
        // better to go through the in inAppBrowser
        // because it does a clean up
        if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
            this.inAppBrowser.goBack();
        }  else {
            // this.inAppBrowser.closeDialog();
        }
    }
}

I don't like this approach I have asked a feature on GitHub; you can follow it on GitHub here: https://github.com/apache/cordova-plugin-inappbrowser/issues/530

like image 60
Irvin Dominin Avatar answered Nov 11 '22 04:11

Irvin Dominin