David Addoteye
David Addoteye

Reputation: 1641

Callback Event for Cordova inAppBrowser

I have an app that access external link through Cordova inAppBrowser. I want a way to listen to an event when a user returns to the app from the external url.

Currently i can listen to event when inAppBrowser is called like so.

        var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
        var myCallback = function(event) { 
                        alert(event.url); 
                    };
       ref.addEventListener('loadstart', myCallback);

I want to listen to an event when user returns to the app from the external link.

Upvotes: 0

Views: 927

Answers (1)

johnborges
johnborges

Reputation: 2533

The load events documented for the InAppBrowser only work with the page you're loading in the InAppBrowser. I'm guessing you want to capture when the user clicks the done button and goes back to the app? If thats the case you should look into handling the exit event.

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

function onDeviceReady() {

    function onExit(){
        alert("InAppBrowser Closed!");
    }    

    var inAppBrowser = cordova.InAppBrowser.open("http://apache.org" ,"_blank", "location=yes");

    inAppBrowser.addEventListener('exit', onExit);
}

Upvotes: 1

Related Questions