当应用程序不处于独立模式时,我想显示一个对话框。我有以下代码:
$(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
});
}
});
问题是该对话框出现,但之后立即关闭,然后返回首页。
主页的pageshow事件发生两次。
如何预防这种行为?
谢谢你的帮助
您需要使用设置延迟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);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句