页面重新加载后保存/传递/获取事件

问题描述 投票:0回答:2

我尝试使用自定义网址方案打开科尔多瓦应用程序。

当我在触发事件后使用它时,它工作得很好,如下所示:

<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,导致应用程序无法打开。

有没有办法通过重新加载页面不丢失事件?

javascript cordova events addeventlistener window.open
2个回答
0
投票

为什么不:

  1. 防止按 Enter 时出现默认行为
  2. 通过ajax发送值
  3. 得到回复
  4. 打开应用程序
  5. 列出项目

结论:

  1. 问题解决了
  2. 无需重新加载页面
  3. 更快的最终结果

0
投票

您可以使用

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 事件触发后注册的任何事件处理程序都会立即调用其回调函数。

© www.soinside.com 2019 - 2024. All rights reserved.