Search code examples
javascriptandroidcordovainappbrowser

Cordova inappbrowser: executeScript on loadstart


Is it possible to executeScript() on loadstart event in Cordova inAppBrowser? Here is my standalone example I made to try to make it happen:

<!DOCTYPE html>
<html>
  <head>
    <title>Standalone Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">
      document.addEventListener("deviceready", onDeviceReady, false);
      var iabRef = null;

      function testFunction() {
        iabRef.executeScript({
          code: {'alert("It is alive! ALIVE!")'}
        });
      }

      function onDeviceReady() {
        iabRef = window.open('http://telegraph.co.uk', '_self', 'location=no', 'zoom=no', 'hardwareback=yes');
        iabRef.addEventListener('loadstart', testFunction);
      }
    </script>
  </head>
  <body>
  </body>
</html>

Doesn't work for me though. Config.xml allow origin is set to *. Any suggestions?

Thanks!


Solution

  • After a little bit of wandering I found that changing "_self" to "_blank" makes it work. So:

    iabRef = window.open('http://telegraph.co.uk', '_blank', 'location=no', 'zoom=no', 'hardwareback=yes');