这是我的代码:
$(window).on('beforeunload', function() {
if ($('.jqmCustomize').css('display') == 'block')
return 'You have not save your customization yet.';
});
这在 chrome 和 firefox 上运行良好,但在 Internet Explorer 上,当我的灯箱在同一页面中打开时,它会触发 on('beforeunload') 事件。有什么办法可以防止这种情况发生吗?我试图:
var close=true;
window.onbeforeunload = closeConfirmation;
function closeConfirmation(){
if(close)
return 'You have not save your customization yet.';
}
但我仍然得到相同的结果。
最佳答案
其实我没有看到任何问题。 可能是我使用的是旧版本的 jqmodal 和 jquery,但它按预期工作:
$(function($){
$('#jqModal').jqm();
$('a').live('click',function(){
$('#jqModal').jqmShow();
return false;
});
});
$(window).on('beforeunload', function() {
if ($('.jqmWindow').css('display') == 'block')
return 'You have not save your customization yet.';
});
HTML:
<a href="/" >Test</a>
<div id="jqModal" class="jqmWindow" style="display: none;">This is the test</div>
关于javascript - 弹出灯箱时,Internet Explorer 触发 'on(beforeunload)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15509847/