【问题标题】:Save/Pass/GET event after page reload页面重新加载后保存/传递/获取事件
【发布时间】:2017-07-06 10:24:05
【问题描述】:

我尝试使用 custom-url-scheme 打开一个cordova-app。

当我在触发事件后使用它时,我可以像这样正常工作:

<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


    【解决方案1】:

    为什么不:

    1. 阻止按 Enter 时的默认行为
    2. 通过 ajax 发送值
    3. 得到响应
    4. 打开应用
    5. 列表项

    结论:

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

    【讨论】:

      【解决方案2】:

      您可以使用ondeviceready 事件来代替DOMContentLoaded 事件。这样,在初始页面(索引页面)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 事件触发后注册的任何事件处理程序都会立即调用其回调函数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多