如何抑制所有 JavaScript 运行时错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7120290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to suppress all JavaScript runtime errors?
提问by Skip
How can I suppress all JavaScript runtime error popups, from the programmers side?
如何从程序员方面抑制所有 JavaScript 运行时错误弹出窗口?
回答by Skip
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.
为了抑制所有 JavaScript 错误,似乎有一个window.onerror
事件。
如果它尽可能早地被一个返回 true 的函数替换(例如在 head 之后) - 将不会有错误弹出窗口,这在调试完成后非常有用。
<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
错误记录也是可能的,如解释here