javascript - 弹出灯箱时,Internet Explorer 触发 'on(beforeunload)'

标签 javascript jquery internet-explorer onbeforeunload

这是我的代码:

$(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,但它按预期工作:

http://jsfiddle.net/xqhLx/5/

$(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/

相关文章:

javascript - 如何通过 "radio"实现 "button"

javascript - 如何使用 requireJs 的多文件库

javascript - 如何选择列表中的嵌套按钮?

IE 中的 CSS 旋转为 "jittery"

html - CSS IE问题

javascript - 使用 ES5 语法在 Node 中混合默认和命名导出

javascript - 如果不存在,则将输入值添加到数组

javascript - 如何使用 jquery 检查是否有任何一个值不等于并停止在每个函数内调用函数?

javascript - 使用 Javascript 或 jQuery 将值全局变量绑定(bind)到对象

javascript - 使用 jQuery 获取选择框 IE 的值。