Difference between revisions of "DOM/window.onerror"

From W3C Wiki
< DOM
Jump to: navigation, search
(creating window.onerror)
 
(Use cases)
Line 5: Line 5:
 
== Use cases ==
 
== 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.
+
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.
 +
 
 +
<nowiki><script src="windowOnerror.js"></script></nowiki>
 +
 
 +
Then in the '''windowOnerror.js'''
 +
 
 +
<nowiki>window.onerror = function myErrorFunction() {
 +
    //the code
 +
    }</nowiki>
 +
 
 +
== Compatibility ==
 +
 
 +
QuirksMode Web site has a [http://www.quirksmode.org/dom/events/error.html compatibility table for '''window.onerror''']
 +
 
 +
* Chrome 13+
 +
* Firefox 6.1+
 +
* Internet Explorer 5.5+
 +
* Opera 12+
 +
* Safari 5.1+

Revision as of 17:57, 21 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() {
    //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+