From W3C Wiki
Jump to: navigation, search


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+