Difference between revisions of "DOM/window.onerror"

From W3C Wiki
Jump to: navigation, search
Line 15: Line 15:
Then in the '''windowOnerror.js'''  
Then in the '''windowOnerror.js'''  
  <nowiki>window.onerror = function myErrorFunction() {
  <nowiki>window.onerror = function myErrorFunction(message, url, linenumber) {
     //the code
     //the code

Revision as of 18:04, 21 October 2011


window.onerror is a handler catching all error events and sending them to the window.

Use cases

The main use case for window.onerror is a simple way to collect programming errors occurring within the page. The context could listen all errors of a Web page and for example send them to a server. In other words, it is a global exception listener which will be invoked if any exception occurs on page.


In the webpage, insert the classical call for a Javascript program.

<script src="windowOnerror.js"></script>

Then in the windowOnerror.js

window.onerror = function myErrorFunction(message, url, linenumber) {
    //the code


QuirksMode Web site has a compatibility table for window.onerror

  • Chrome 13+
  • Firefox 6.1+
  • Internet Explorer 5.5+
  • Opera 12+
  • Safari 5.1+