我的ASP.NET网页上有以下脚本,用于在用户从未保存的更改导航离开页面时发出警告。onbeforeunload消息出现两次(Internet Explorer)
$(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 runtime error: Unspecified error.
这个问题似乎是具体到Internet Explorer。在网络搜索中,我能够找到许多关于相关错误的参考资料,令人难以置信地返回几个版本的Internet Explorer。但是,我无法从Microsoft或任何合理的解决方法中找到任何评论。以下是我发现的几个相关链接。
- 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
上帝派,永远不会想出来...... –
我在IE浏览器中的unbeforeload问题越来越沮丧,但这种解决方案像一个冠军!谢谢!! –