DOM/window.onerror

From W3C Wiki
< DOM
Revision as of 18:04, 21 October 2011 by Karl (Talk | contribs)

Jump to: navigation, search

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+