2

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:

  • The url opened is such as 'file://...'
  • If I set 'location=yes' and push the 'done' button, It tries to close but reappears.
Community
  • 1
  • 1
Brian
  • 349
  • 1
  • 5
  • 16

1 Answers1

1

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
     }
}
Leo
  • 1,495
  • 23
  • 41