Dialog closes directly after open

三世轮回 提交于 2020-01-05 10:08:07

问题


I want to show a dialog when an app is not in standalone mode. I have this code:

$(document).on("pageinit", "#home", function (e) {
  console.log('pageinit');
  if (!window.navigator.standalone && (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i))) {
    $.mobile.changePage('/mobile/install', {
        role: 'dialog',
        showLoadMsg: true,
        changeHash: false
    });
   }
});

The problem is that the dialog appears but close directly after and it returns to homepage.

The pageshow event for homepage happens twice.

How to prevent this behavior ?

Thanks for your help


回答1:


You need to set delay using setTimeout.

$(document).on("pageinit", "#home", function (e) {
 if (!window.navigator.standalone && (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i))) {
  setTimeout(function () {
    $.mobile.changePage('/mobile/install', {
      role: 'dialog',
      showLoadMsg: true,
      changeHash: false
    });
  }, 100);
 }
});


来源:https://stackoverflow.com/questions/17762078/dialog-closes-directly-after-open

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!