我尝试使用自定义网址方案打开科尔多瓦应用程序。
当我在触发事件后使用它时,它工作得很好,如下所示:
<input id="myInput" onkeydown="checkKey(event);"/>
function checkKey(event) {
if (event.which == 13 || event.keyCode == 13) {
window.open('blablabla'); // call the App
}
};
不幸的是,在我的情况下,按 Enter 键后,必须由后端系统检查该值,然后重新加载页面。
所以我尝试了这个:
document.addEventListener('DOMContentLoaded', function() {
window.open('blablabla'); // call the App
}, false);
这里的问题是没有活动事件,所以chrome做了一个navigation.block,导致应用程序无法打开。
有没有办法通过重新加载页面不丢失事件?
为什么不:
结论:
您可以使用
DOMContentLoaded
事件代替 ondeviceready
事件。在其中,在初始页面(索引页面)onDeviceReady()
,您可以进行验证并随后调用应用程序的第一页。
我们通常在将用户引导至应用程序主页之前对登录页面执行此操作。例如-
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
//get the value
//check event through backend system
window.open('blablabla'); //call the App's first page
}
引用自
[deviceready][1]
文档-
deviceready 事件的行为与其他事件有所不同。 deviceready 事件触发后注册的任何事件处理程序都会立即调用其回调函数。