window.onerror不起作用 [英] window.onerror does not work

查看:788
本文介绍了window.onerror不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一些棘手的AJAX代码,有时它会失败(不要问为什么,我不能绕过它)。当这种情况发生时,我需要捕获错误,重置一个隐藏的字段指示符,并自然提交表单,以便用户不会有不愉快的体验。我计划使用 window.onerror 来做到这一点,但是它永远不会触发!我正在使用IE8,所有我必须担心的是IE浏览器。有没有办法让这个事件工作?这是我的代码...

I have some tricky AJAX code on a form, and sometimes it will fail (don't ask why, I can't get around it). When this happens, I need to trap the error, reset a hidden field indicator, and submit the form naturally so that the user does not have an unpleasant experience. I planned on using window.onerror to do this, but it is never firing! I am using IE8 and all I have to worry about is the IE browser. Is there some gotcha to getting this event to work? Here's my code...

window.onerror = function() {
  alert("Error!");
  document.getElementById("hidAjax").value = "0";
  document.forms[0].submit();
}


推荐答案

一个常见的问题许多开发人员发生在他们的onerror处理程序没有被调用时,因为它们启用了Internet Explorer的脚本调试,如果你已经安装了Microsoft Script Debugger或者Microsoft Visual Studio6.0®(特别是Visual InterDev 6.0™),那么默认情况就是这样 - 处理这些产品是如何启动调试器的。您可以在Internet选项对话框的高级选项卡上禁用给定的Internet Explorer实例的脚本调试(请注意,检查禁用脚本调试设置仅适用于该Internet Explorer实例) :

"A common problem that bites many developers occurs when their onerror handler is not called because they have script debugging enabled for Internet Explorer. This will be the case by default if you have installed the Microsoft Script Debugger or Microsoft Visual Studio 6.0® (specifically Visual InterDev 6.0™)—onerror handling is how these products launch their debugger. You can disable script debugging for a given instance of Internet Explorer on the Advanced tab of the Internet Options dialog box (note that checking the Disable script debugging setting will apply only to that instance of Internet Explorer):"

http: //msdn.microsoft.com/en-us/library/ms976144.aspx

这篇关于window.onerror不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆