Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android InAppBrowser _system callbacks

I have been developing a mobile app for Android/IOS/Windows 8 in Cordova that needs to pass a few strings to a web page. Unfortunately for me, the web page does not support TLS 1.0 protocol, which means older Android versions (and IOS versions) cannot open the page within the native browser.

This means the window.open call, when set to '_blank', will not load the page on any Android version before 16 API, and it's only really guaranteed for 19 API and above:

window.open('https://www.libertymountain.com/login.aspx','_blank') 

My solution was to change it to "_system" instead of "_blank". This works, because the phone can use the chrome or safari browser instead of the native browser. However, when I do this, all of the callbacks cease to work. It just opens up the page, and I can't run the script on it.

For example, the code below does NOT ever execute the callback. It merely opens the webpage:

var ref = window.open('https://www.libertymountain.com/login.aspx','_system');
ref.addEventListener('loadstart', function() { alert("Hello"); });

Am I missing something, or is there a proper way to do this?

EDIT: Just to make it clear, this is my code that never triggers the callback:

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

function init() {
    window.open = cordova.InAppBrowser.open;
    var ref = window.open('https://www.libertymountain.com/login.aspx', '_system');
    // This event never triggers, nor does any other event, even though the
    // webpage is opened in Chrome
    websiteReference.addEventListener('loadstart', function(event) { console.log('Hello'); });
}

If I change it to this, the events do trigger. But I need to do it with '_system' otherwise older Android and IOS devices won't be able to do it.

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

function init() {
    window.open = cordova.InAppBrowser.open;
    // Change '_system' to '_blank'
    var ref = window.open('https://www.libertymountain.com/login.aspx', '_blank');
    // This event never triggers, nor does any other event, even though the
    // webpage is opened in Chrome
    websiteReference.addEventListener('loadstart', function(event) { console.log('Hello'); });
}
like image 567
NineToYourSpine Avatar asked Nov 10 '22 09:11

NineToYourSpine


1 Answers

I heard that you can't actually execute scripts or trigger callbacks in the external system browsers (when using the '_system' option for InAppBrowser window.open()). From my testing, this seems to be true. On the other hand, '_blank' does of course trigger callbacks because it is using the native browser within the app.

like image 56
NineToYourSpine Avatar answered Nov 14 '22 22:11

NineToYourSpine