最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I detect if the browser has encountered a JavaScript error ... in JavaScript? - Stack Overflow

programmeradmin2浏览0评论

For automated testing reasons I want to detect if the browser has encountered JavaScript errors for a page. The type of things that would cause the red numbers in the bottom right in Firebug or yellow warning icon in the Internet Explorer status bar. These JS errors could come from any one of a large numbers of scripts.

How in JavaScript can I detect these browser errors? Cross browser solutions prefered, but hey, I'll take anything!

As a bonus it would also be great to know the script that caused the error.

For automated testing reasons I want to detect if the browser has encountered JavaScript errors for a page. The type of things that would cause the red numbers in the bottom right in Firebug or yellow warning icon in the Internet Explorer status bar. These JS errors could come from any one of a large numbers of scripts.

How in JavaScript can I detect these browser errors? Cross browser solutions prefered, but hey, I'll take anything!

As a bonus it would also be great to know the script that caused the error.

Share Improve this question asked Apr 2, 2010 at 20:27 RichHRichH 6,1382 gold badges39 silver badges62 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 18

window.onerror handler is the answer. Read this - http://www.javascriptkit.com/javatutors/error.shtml

To get more information about the script that caused the error, read this - http://www.javascriptkit.com/javatutors/error3.shtml

发布评论

评论列表(0)

  1. 暂无评论