Brian
Brian

Reputation: 349

How can I close the inAppbrowser with a button not done button topbar

I can't figure out of this. I've opened a child browser in phonegap for android app:

window.open( url, '_blank', 'location=yes' );

this is not quite right. It opens the browser, but the done button doesn't close the browser and not returns to the main application.

I've tried with another solution that I've found:

window.close equivalent in Phonegap with InAppBrowser:

This code is the the phonegap app:

var ref = window.open(encodeURI(url), '_blank', options);
ref.addEventListener('loadstop', function(event) {        
    if (event.url.match("mobile/close")) {
        ref.close();
    }
});

This button is created in the url page that I've loaded previously:

<a href="/mobile/close">Close</a>

It doesn't work. Any help?

Update:

Upvotes: 2

Views: 8648

Answers (1)

Leo
Leo

Reputation: 1505

I got this to work. My code is similar but here are the things I did diferently I used loadstart instead of loadstop. I also removed the events.

function iabWindowOpen(url) {
    //May need to encodeURI on iOS so far working fine on android
    g_iabRef = window.open(url, "_blank", "location=yes,closebuttoncaption=Cancel");
    g_iabRef.addEventListener('loadstart', iabLoadStart);
    g_iabRef.addEventListener('loaderror', iabError);
    g_iabRef.addEventListener('exit', iabExit);
}


function iabLoadStart(event){
    var url = event.url;
    LOG ('iabLoadStart - ' + url);
    var iOut = url.indexOf("CloseIAB"); //or whatever you are looking for in your url
    if(iOut >= 0){
         g_iabRef.removeEventListener('loadstart', iabLoadStart);
         g_iabRef.removeEventListener('loaderror', iabError);
         g_iabRef.removeEventListener('exit', iabExit);
         g_iabRef.close();
         handleOpenURL(url); //do what you want when you get back
     }
}

Upvotes: 1

Related Questions