tips:cordova:inappbrowser

inAppBrowser

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

In src/com/org/apache/corodova/inappbrowser/InAppBrowser.java change

private void goBack() {
   if (this.inAppWebView.canGoBack()) {
      this.inAppWebView.goBack();
   }
}

to (public method)

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

src/com/org/apache/corodova/inappbrowser/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();
      }
   }
}

Enable video autplay without gestures

In file src/com/org/apache/corodova/inappbrowser/InAppBrowser.java add (~647 row)

  inAppWebView.loadUrl(url);
  inAppWebView.setId(6);
  inAppWebView.getSettings().setLoadWithOverviewMode(true);
  inAppWebView.getSettings().setUseWideViewPort(true);
+ inAppWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);

Looping mode does not work, add this hack to javascript and add looping=“loop” attribute to video tag

    var videos = jQNew( "video[looping='loop']" );
    for (index = 0; index < videos.length; ++index) {
       videos[index].addEventListener('ended', function (e) {window.location.reload();},false);
    }
  • tips/cordova/inappbrowser.txt
  • Last modified: 2015/03/27 17:40
  • by scipio