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

**URL:** <https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692>\
**Category:** ionic-v1\
**Created:** [September 17, 2017, 4:28am UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692 "2017-09-17T04:28:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tajkumar](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@Tajkumar](https://forum.ionicframework.com/u/Tajkumar)\
**Post date:** [September 17, 2017, 4:28am UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692/1 "2017-09-17T04:28:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sarikonda1](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@sarikonda1](https://forum.ionicframework.com/u/sarikonda1)\
**Post date:** [February 27, 2018, 1:51pm UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692/2 "2018-02-27T13:51:17Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![felix9607](https://avatars.discourse-cdn.com/v4/letter/f/0ea827/32.png) [@felix9607](https://forum.ionicframework.com/u/felix9607)\
**Post date:** [February 27, 2018, 2:06pm UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692/3 "2018-02-27T14:06:56Z")

</div>

```auto
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();
      }
    });

```

---

<div class="post-metadata">

**Author:** ![sarikonda1](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@sarikonda1](https://forum.ionicframework.com/u/sarikonda1)\
**Post date:** [February 27, 2018, 2:30pm UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692/4 "2018-02-27T14:30:52Z")

</div>

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 … !

---

<div class="post-metadata">

**Author:** ![ankit18singh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ankit18singh/32/119550_2.png) [@ankit18singh](https://forum.ionicframework.com/u/ankit18singh)\
**Post date:** [October 24, 2018, 1:21pm UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692/5 "2018-10-24T13:21:47Z")

</div>

for iOS set target as “\_self”

---

<div class="post-metadata">

**Author:** ![ankit18singh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ankit18singh/32/119550_2.png) [@ankit18singh](https://forum.ionicframework.com/u/ankit18singh)\
**Post date:** [October 24, 2018, 1:22pm UTC](https://forum.ionicframework.com/t/how-to-get-the-url-from-the-event-listener-in-cordova-inapp-browser-event-and-close-it-after-reaching-a-specific-url/105692/6 "2018-10-24T13:22:22Z")

</div>

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