How to get the url from the event listener in cordova inapp browser event? and close it after reaching a specific url

Here is my code of closing the in app browser after reaching a specific URL in ionic version 1 (BTW i am new to ionic & angularjs). Here my problem is the event raised on “loadstart” is MouseEvent i couldn’t find any url in the object i am getting undefined error on console.log(event.url) . I tried with Loadstop and exit too in the event listener.

   document.addEventListener("deviceready", onDeviceReady, false);

  function onDeviceReady() {

  function onExit(event) {

      var urlSuccessPage = "https://tick.com/s";
      alert(event);
      alert(event.url);

      console.log(event.url);
      console.log(event);
      if (event.url == urlSuccessPage) {

          inAppBrowser.close();
      }
  }

  var inAppBrowser = window.open("https://tick.com", "_blank", "location=yes");

 inAppBrowser.addEventListener('loadstart', onExit(event));


 }

Thanks in advance

The events are not firing on loadstar & loadstop event of InAppBrowser on time but calling after closing browser . please give suggestion to get events url on browser window and I also used _blank in Url ?

let yourUrl;
let theOtherUrl;
const browser: InAppBrowserObject = this.iab.create(yourUrl, "_blank", "hidden=no,location=no,clearsessioncache=yes,clearcache=yes"); //no spaces allowed in Options!


    browser.on('loadstart').subscribe((e) => { 
      console.log(e.url);
      if (e.url == theOtherUrl) {
        browser.close();
      }
    });
1 Like

Hi felix9607,

Thanks for reply,

I already tried this getting same problem.I am unable to get the url which is loading in the browser.The same code which you posted is working fine for android but not for iOS.

Thanks in Advance … !

for iOS set target as “_self”

1 Like

can we track the same event when platform is not cordova.?

1 Like