Hi,
I am using InAppBrowser on my ionic1 app to login to Instagram by using window.open and ‘_blank’. There are a couple of redirects until it reaches “my_own_url_redirected_from_instagram” which are well detected in loadstart event.
The objective is to pass some data from the opened page to the app.
But my issue is the loadstop event which is not triggered (seems kind of random) even if the page finishes loading. It seems like a refreshing issue of the inAppBrowser page. Actually this event (and often also some loadstart events which were not triggered before - related to Instagram redirects) is triggered when I click on the ‘Done’ button in the bottom toolbar of the window. And this is a problem before I want to execute a script on this page before it closes.
I am testing it directly on iOS 9.3.
What am I doing wrong ?
Thanks a lot for your help
My code :
win = window.open(url_to_oath_instagram,'_blank', 'location=no,toolbar=yes');
function exit() {
console.log('Exiting...');
win.removeEventListener('loadstart', loadStart);
win.removeEventListener('loadstop', loadStop);
win.removeEventListener('loaderror', loadError);
win.removeEventListener('exit', exit);
}
function loadError(event) {
console.log(event);
}
function loadStart(event) {
console.log('Starting load...');
console.log('URL : ', event.url);
}
function loadStop(event) {
console.log(event);
if(event.url.indexOf('my_own_url_redirected_from_instagram') != -1) {
win.executeScript({ code: "document.body.innerHTML" }, function (values) {
console.log(values); // and do stuff with values[0]
win.close();
});
}
}
win.addEventListener("loadstop", loadStop);
win.addEventListener("loaderror", loadError);
win.addEventListener('loadstart', loadStart);
win.addEventListener('exit', exit);