Android InAppBrowser _system回调 [英] Android InAppBrowser _system callbacks

查看:94
本文介绍了Android InAppBrowser _system回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Cordova开发Android / IOS / Windows 8的移动应用程序,需要将一些字符串传递给网页。不幸的是,网页不支持TLS 1.0协议,这意味着较旧的Android版本(和IOS版本)无法在本机浏览器中打开页面。

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.

这意味着当设置为'_blank'时,window.open调用将不会在16 API之前的任何Android版本上加载页面,并且它只能保证19 API及以上:

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

我的解决方案是将其更改为_system而不是_blank。这是有效的,因为手机可以使用chrome或safari浏览器而不是本机浏览器。但是,当我这样做时,所有的回调都停止工作。它只是打开页面,我无法在其上运行脚本。

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?

编辑:为了说清楚,这是我的代码永远不会触发回调:

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

如果我将其更改为此,则会触发事件。但我需要使用'_system'来实现,否则较旧的Android和IOS设备将无法执行此操作。

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


推荐答案

我听说你可以'实际上在外部系统浏览器中执行脚本或触发回调(当使用InAppBrowser window.open()的'_system'选项时)。从我的测试来看,这似乎是真的。另一方面,'_ blank'当然会触发回调,因为它正在使用应用程序中的本机浏览器。

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.

这篇关于Android InAppBrowser _system回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆