如何抑制所有JavaScript运行时错误? [英] How to suppress all JavaScript runtime errors?

查看:217
本文介绍了如何抑制所有JavaScript运行时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从程序员端抑制所有JavaScript运行时错误弹出窗口?

How can I suppress all JavaScript runtime error popups, from the programmers side?

推荐答案

要抑制所有JavaScript错误,似乎成为 window.onerror 事件。

如果它被一个返回true的函数尽早替换(例如在头部之后) - 将不会出现错误弹出窗口,这在调试完成后非常有用。

To suppress all JavaScript errors there seems to be a window.onerror event.
If it is replaced as early as possible(e.g. right after the head) by a function which returns true - there will be no error popups, which is quite useful after debugging is done.

<head>
<script type="text/javascript">
    window.onerror = function(message, url, lineNumber) {  
        // code to execute on an error  
        return true; // prevents browser error messages  
    };
</script> 
...

错误记录也是可能的,如这里

Error Logging is possible too, as explained here

这篇关于如何抑制所有JavaScript运行时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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