相关疑难解决方法(0)

onbeforeunload消息出现两次(Internet Explorer)

我在ASP.NET网页上有以下脚本,用于在用户离开未保存更改的页面时向用户发出警告.

$(document).ready(function() {
    $('input:not(:button,:submit),textarea,select').change(function () {
        window.onbeforeunload = function () {
            return 'Changes made to this page have not been saved!';
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

除了用户使用Internet Explorer并尝试使用类似此链接导航之外的一些问题时,此功能与预期一致.

<div onclick="window.location=&#39;http://www.domain.com&#39;;">Text</div>
Run Code Online (Sandbox Code Playgroud)

如果用户选择"留在此页面上",则会出现两次消息框.然后,如果他们第二次选择"留在此页面上",调试器会使用以下消息突​​出显示上面的链接:

Microsoft JScript运行时错误:未指定的错误.

此问题似乎特定于Internet Explorer.在网上搜索,我已经能够找到许多类似错误的参考资料,令人难以置信地回溯了几个版本的Internet Explorer.但是,我无法找到微软的任何评论或合理的解决方案.以下是我发现的一些相关链接.

  1. http://forums.asp.net/t/1199756.aspx/1
  2. 为什么我的onbeforeunload处理程序导致"未指定的错误"错误?
  3. http://www.telerik.com/community/forums/aspnet-ajax/tabstrip/cancel-on-onbeforeunload-in-ie-6-7-create-js-unspecified-error.aspx
  4. http://scottonwriting.net/sowblog/archive/2005/04/19/163068.aspx
  5. http://www.techtalkz.com/internet-explorer/116662-onbeforeunload-dialog-cancel-button-when-window-location-href-bug.html
  6. http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14213927
  7. http://www.webmasterkb.com/Uwe/Forum.aspx/jscript/4321/IE7-and-onbeforeunload
  8. http://www.bigresource.com/ASP-Javascript-Unspecified-Error-BHoy7ptS.html
  9. http://www.4guysfromrolla.com/articles/042005-1.aspx

任何人都可以建议解决方法?看起来Connect不接受IE错误报告.我正在使用IE9

javascript jquery internet-explorer

4
推荐指数
1
解决办法
3604
查看次数

标签 统计

internet-explorer ×1

javascript ×1

jquery ×1