In my phonegap app, I open with InAppBrowser an external link (it correctly works) with:
cordova.InAppBrowser.open(completeUrl, '_blank', 'location=yes');
I need to close the opened link when a certain actions is made by the user. I know I can close it with
var b = cordova.InAppBrowser.open(completeUrl, '_blank', 'location=yes');
b.Close();
but this is on my app side, I need something similar on external link side. For example, is it possible to have the instance reference on the external link side? I think no, right?
With "location=yes" I have a confortable close button on the top, so this can be a solution, but I'd like to close it when the user finishes to use the external link, without using the native close button.
Is it possible?
UPDATE What did I try? 1) From window.close equivalent in Phonegap with InAppBrowser For example my server display a webpage with a close button, something like this:
<a href="/mobile/close">Close</a>
in my client side javascript (the Phonegap app):
var ref = window.open(encodeURI(url), '_blank', options);
ref.addEventListener('loadstop', function(event) {
if (event.url.match("mobile/close")) {
ref.close();
}
});
2) From https://stackoverflow.com/a/50047473/819161
var win=window.open( "myurl", "_blank");
win.addEventListener( "loadstop", function(){
var loop = window.setInterval(function(){
win.executeScript({
code: "window.shouldClose"
},
function(values){
if(values[0]){
win.close();
window.clearInterval(loop);
}
}
);
},100);
});
In your called window, simply do:
window.shouldClose=true
When you want to close it
3) A dumb window.Close() from the called page
Nothing of my attempts worked.
In order to close the InAppBrowser window by itself, you can either use the loadstart
or the message
event listeners.
Check details and full examples here: How to close InAppBrowser window in Cordova by itself