【问题标题】:Setting window.onbeforeunload to undefined in IE8 causes" not implemented error在 IE8 中将 window.onbeforeunload 设置为未定义导致“未实现错误
【发布时间】:2013-06-11 12:43:51
【问题描述】:
            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 应声明为局部变量以解决此问题——但我不确定如何。

谁能向我解释这个错误和可能的解决方案?

谢谢!

【问题讨论】:

  • 嗯,不要那样做?你想做什么?
  • 已编辑问题以显示更多细节

标签: javascript jquery internet-explorer internet-explorer-8 onbeforeload


【解决方案1】:
window.onbeforeunload = function(){};

【讨论】:

    【解决方案2】:

    试试这个:

    $(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 处理程序并不是最好的主意。

    【讨论】:

    • 这个解决方案的一个问题......现在,Resharper 唠叨我要返回一些东西;)
    【解决方案3】:

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

    您可以简单地将其设置为不返回任何内容的函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 1970-01-01
      • 2012-07-06
      相关资源
      最近更新 更多