Android InAppBrowser _system callbacks

情到浓时终转凉″ 提交于 2019-12-23 09:44:56

问题


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'); });
}

回答1:


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.




回答2:


In order to run script on another file you need to load that file first like this:-

var ref = window.open('http://www.libertymountain.com/','_system');
$(ref .document).load(function() {
    alert('Hello');
    // do other things
});

OR +-------

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

// device APIs are available
//
function onDeviceReady() {
     var ref = window.open('http://www.libertymountain.com/','_system');
     ref.addEventListener('loadstart', function(event) { alert('Hello'); });
}


来源:https://stackoverflow.com/questions/31420935/android-inappbrowser-system-callbacks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!