设置窗口.在IE8中未定义的onbeforeunload原因"未实现错误

Setting window.onbeforeunload to undefined in IE8 causes" not implemented error

本文关键字:quot 错误 实现 原因 onbeforeunload 窗口 IE8 未定义 设置      更新时间:2023-09-26
            if(!$('fieldset.quote-step4').hasClass('show')) {
                window.onbeforeunload = function() {
                    return "Are you sure you want to leave the quote request page? This will reset the form.";
                }
            } else {
                window.onbeforeunload = undefined;
            }

我在一个私有函数内部的脚本中有上述内容,这会导致ie8中的"未实现"错误。

导致错误的具体行是:window.onbeforeunload = undefined;

从我在其他问题中读到的window应该被声明为一个局部变量来解决这个问题——但我不确定如何。

谁能给我解释一下这个bug和一个可能的解决方案?

谢谢!

试试这个:

$(window).on('beforeunload', function() {
   if($('fieldset.quote-step4').hasClass('show')) {
        return;
   }
   return "Are you sure you want to leave the quote request page? This will reset the form.";
});
当jQuery已经在您的页面上时,使用DOM1处理程序并不是最好的主意。
window.onbeforeunload = function(){};

onbeforeunload是一个事件处理程序;很明显;IE8不喜欢清除它

您可以简单地将它设置为一个不返回任何东西的函数。