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

查看:30
本文介绍了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 Studio 6.0®(特别是 Visual InterDev 6.0™)—onerror 处理是这些产品启动其调试器的方式.您可以在Internet 选项对话框(请注意,选中禁用脚本调试设置将仅适用于该 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天全站免登陆