【发布时间】:2011-08-02 18:52:50
【问题描述】:
我的 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!';
}
});
});
除了当用户使用 Internet Explorer 并尝试使用类似这样的链接离开时出现一些问题外,这与预期的效果一样。
<div onclick="window.location='http://www.domain.com';">Text</div>
如果用户选择“留在此页面上”,则消息框会出现两次。然后,如果他们第二次选择“留在此页面上”,调试器会突出显示上面的链接并显示消息:
Microsoft JScript 运行时错误:未指定的错误。
此问题似乎特定于 Internet Explorer。在网上搜索,我已经能够找到许多关于似乎相关错误的参考,令人难以置信的是可以追溯到 Internet Explorer 的几个版本。然而,我找不到来自微软的任何评论或合理的修复。以下是我发现的一些相关链接。
- http://forums.asp.net/t/1199756.aspx/1
- Why is my onbeforeunload handler causing an "Unspecified error" error?
- http://www.telerik.com/community/forums/aspnet-ajax/tabstrip/cancel-on-onbeforeunload-in-ie-6-7-create-js-unspecified-error.aspx
- http://scottonwriting.net/sowblog/archive/2005/04/19/163068.aspx
- http://www.techtalkz.com/internet-explorer/116662-onbeforeunload-dialog-cancel-button-when-window-location-href-bug.html
- http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14213927
- http://www.webmasterkb.com/Uwe/Forum.aspx/jscript/4321/IE7-and-onbeforeunload
- http://www.bigresource.com/ASP-Javascript-Unspecified-Error-BHoy7ptS.html
- http://www.4guysfromrolla.com/articles/042005-1.aspx
任何人都可以提出解决方法吗?看起来 Connect 不接受 IE 错误报告。我用的是IE9
【问题讨论】:
标签: javascript jquery internet-explorer