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

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

问题描述

我有一个表格上的一些棘手的AJAX code,有时候它会失败(不要问为什么,我不能绕过它)。发生这种情况时,我需要捕获错误,重新设置一个隐藏字段的指标,并提交表单,自然让用户没有不愉快的经历。我计划使用 window.onerror 要做到这一点,但它永远不会开火!我使用IE8和我所担心的是IE浏览器。有一些疑难杂症,以获得本次活动的工作?这是我的code ...

  window.onerror =功能(){
  警报(错误!);
  。的document.getElementById(hidAjax)值=0;
  document.forms [0] .submit();
}
 

解决方案

这叮咬许多开发人员时,他们的onerror处理程序不被调用,因为他们有对Internet Explorer启用脚本调试时出现一个常见的​​问题,这将是默认的情况下,如果您已经安装了Microsoft脚本调试程序或Microsoft Visual Studio6.0®(具体的Visual InterDev 6.0™)-onerror处理是如何将这些产品的推出自己的调试器,你可以的高级选项卡上的Internet Explorer的给定实例禁用脚本调试Internet选项对话框中(注意选中禁用脚本调试设置将仅适用于Internet Explorer的实例):

<一个href="http://msdn.microsoft.com/en-us/library/ms976144.aspx">http://msdn.microsoft.com/en-us/library/ms976144.aspx

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();
}

解决方案

"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天全站免登陆