2

I'm writing a mobile application using cordova 3.6, this app just open an external url corresponding to the mobile version of my website

var ref = window.open('http://www.stackoverflow.com', '_self', 'location=no');

If a use _self as the target, the back button behavior is fine forme as it works correctly within browesed pages but the problem is that the last back in the history stack done go back on my index page and then open once again my url ! Also the events on the window doesn't work. How to exit?

var ref = window.open('http://www.stackoverflow.com', '_blank', 'location=no');

If a use _self as the target, the back button behavior is not the same. There is no back possible within browsed pages, just a back on the index page whatever we are. How can I modify the behavior to have the same as the _self?

I am stuck with these 2 solutions :(

Note: I saw this similar question but the suggested code

dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    public void onDismiss(DialogInterface dialog) {     
                        closeDialog();
                    }
});

no more exists in cordova InAppBrowser.java no more exist

Community
  • 1
  • 1
Crio
  • 101
  • 1
  • 7

1 Answers1

3

I found a working solution for the "_blank" option target using cordova 3.6 thanks to the answer of Kris Erikson on this post

With those modifications the hardware back button works within pages in an InAppBrowser.

I copy hereafter his working solution

Go to src/com/org/apache/corodova/inappbrowser directory and edit the InAppBrowserDialog.java: Change

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

to

public void onBackPressed () {
   if (this.inAppBrowser == null) {
      this.dismiss();
   } else {
      if (this.inAppBrowser.canGoBack()) {
         this.inAppBrowser.goBack();
      }  else {
         this.inAppBrowser.closeDialog();
      }
   }
}

Then go to InAppBrowser and find the goBack function, change:

/**
* Checks to see if it is possible to go back one page in history, then does so.
*/
private void goBack() {
   if (this.inAppWebView.canGoBack()) {
      this.inAppWebView.goBack();
   }
}

to

/**
* Checks to see if it is possible to go back one page in history, then does so.
*/
public void goBack() {
   if (this.inAppWebView.canGoBack()) {
      this.inAppWebView.goBack();
   }
}

public boolean canGoBack() {
   return this.inAppWebView.canGoBack();
}

Please post if you find a better solution avoiding to modify the java code

Community
  • 1
  • 1
Crio
  • 101
  • 1
  • 7