每次加载页面时,我的 jQuery 移动对话框都会打开。即使将 cookie 设置为仅打开一次且不再打开,它也会在每次刷新时继续打开。我不知道为什么它在没有任何触发器的情况下加载?任何帮助,将不胜感激。
JAVASCRIPT
function openDialog() {
var interval = setInterval(function(){
$.mobile.changePage('#dialog');
clearInterval(interval);
},1);
}
$(function() {
if ($.cookie('dialog_shown') == null) {
$.cookie('dialog_shown', 'yes', { expires: 7, path: '/' });
$(document).on('pageshow', '#index', function(){
openDialog();
});
}
});
HTML
<body>
<div data-role="dialog">
<div data-role="header" data-theme="d">
<h1>Custom Dialog</h1>
</div>
<div data-role="content">
<h1>Customize the HTML. Have any content you want in here.</h1>
<p>This is a regular page, styled as a dialog. To create a dialog, just link to a normal page and include a transition and <code>data-rel="dialog"</code> attribute.</p>
<a href="#index" data-role="button" data-theme="b">Button Style</a>
<a href="#index" data-role="button" data-theme="c">Cancel</a>
</div>
</div>
<div data-role="page" id="index">
</div>
</body>