问题
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