打开后对话框立即关闭 [英] Dialog closes directly after open

查看:68
本文介绍了打开后对话框立即关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序不处于独立模式时,我想显示一个对话框.我有以下代码:

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.

首页的pageshow事件发生两次.

The pageshow event for homepage happens twice.

如何防止这种行为?

感谢您的帮助

推荐答案

您需要使用 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);
 }
});

这篇关于打开后对话框立即关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆