Difference between revisions of "DOM/window.onerror"

From W3C Wiki
< DOM
Jump to: navigation, search
(Example)
(Compatibility)
 
Line 26: Line 26:
 
* Firefox 6.1+
 
* Firefox 6.1+
 
* Internet Explorer 5.5+
 
* Internet Explorer 5.5+
* Opera 12+
+
* (Opera 12+ ?)
 
* Safari 5.1+
 
* Safari 5.1+

Latest revision as of 13:41, 25 October 2011

Description

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.

Example

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
    }

Compatibility

QuirksMode Web site has a compatibility table for window.onerror

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