window.onerror does not work in Safari

// Declare Error Handler
function oops()
{
  alert ('Error!');
  return true;
}

// Assign to global error handler
window.onerror = oops;

// Trigger an error
x.y.z();

This does not work, and it makes me sad.

Updated – removed syntax error from example

About James McParlane

CTO Massive Interactive. Ex Computer Whiz Kid - Now Grumpy Old Guru.
This entry was posted in JavaScript. Bookmark the permalink.

5 Responses to window.onerror does not work in Safari

  1. Thogek says:

    As far as I can tell, this is still the case, and still frustrating…

    Any word on whether it might someday change?

  2. Robert Stroud says:

    I pasted your example into the latest version of Safari and it appeared to work…

    But alas, there’s a bug in your example – it should be

    window.onerror = oops

    and it’s still not working… 😦

  3. Samuel Lebeau says:

    Actually, window.onerror is not part of any specification

  4. Chuck Houpt says:

    Four year later, and Safari still doesn’t have window.onerror, even though it is now part of the HTML spec.
    As a kludgy work-around, I’ve put together genericOnError, which emulates window.onerror for Safari and Opera.
    It won’t make you happy, just a little less sad.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s