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

Javascript 页面重新加载后保存/传递/获取事件,javascript,cordova,events,addeventlistener,window.open,Javascript,Cordova,Events,Addeventlistener,Window.open,我尝试打开一个带有自定义url方案的cordova应用程序 当我在触发事件后使用它时,我的工作方式如下: <input id="myInput" onkeydown="checkKey(event);"/> function checkKey(event) { if (event.which == 13 || event.keyCode == 13) { window.open('blablabla'); // call the App } };

我尝试打开一个带有自定义url方案的cordova应用程序

当我在触发事件后使用它时,我的工作方式如下:

<input id="myInput" onkeydown="checkKey(event);"/>

function checkKey(event) {
    if (event.which == 13 || event.keyCode == 13) {
        window.open('blablabla'); // call the App
    }
};
这里的问题是没有活动事件,所以chrome会进行导航。阻止无法打开应用程序

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

为什么没有:

  • 阻止按enter键时的默认行为
  • 通过ajax发送值
  • 得到回应
  • 打开应用程序
  • 列表项
  • 结论:

  • 问题解决
  • 不需要重新加载页面
  • 更快的最终结果

  • 您可以使用
    ondevicerady
    event来代替
    DOMContentLoaded
    event。这样,在初始页面(索引页面)
    ondevicerady()
    上,您可以进行验证,然后调用应用程序的第一页

    我们通常在将用户引导到应用程序的主页面之前对登录页面执行此操作。比如说-

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        //get the value
        //check event through backend system
         window.open('blablabla');  //call the App's first page
    }
    
    引用自
    [devicerady][1]
    文档-

    deviceready事件的行为与其他事件有所不同在deviceready事件触发后注册的任何事件处理程序都会立即调用其回调函数。

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        //get the value
        //check event through backend system
         window.open('blablabla');  //call the App's first page
    }