我正在使用Cordova开发一款Android/iOS/Windows 8移动应用,需要将一些字符串传递给网页。不幸的是,该网页不支持TLS 1.0协议,这意味着旧版Android(和iOS版本)无法在本机浏览器中打开该页面。
这意味着当window.open调用设置为'_blank'时,任何Android 16 API版本之前的版本都无法加载该页面,并且仅在19 API及以上版本上才真正保证可行:
window.open('https://www.libertymountain.com/login.aspx','_blank')
我的解决方案是将"_blank"更改为"_system"。这样可以使用Chrome或Safari浏览器而不是本地浏览器,但是这样做后,所有的回调都停止工作了。它只是打开页面,我无法在其上运行脚本。
例如,下面的代码永远不会执行回调函数,它只是打开网页:
var ref = window.open('https://www.libertymountain.com/login.aspx','_system');
ref.addEventListener('loadstart', function() { alert("Hello"); });
我有点不明白,还是说有一种正确的方法来做这件事吗?
编辑:为了明确起见,这是我的代码,从未触发回调:
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设备将无法执行此操作。
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'); });
}