Take the 2-minute tour ×

... in Safari

I've tried both preventDefault and stopPropagation but neither works.

        window.addEventListener("error", function (event) {
            if ( event.target.tagName === 'IMG' ) {
                event.target.src = 'fake_path';
                // event.preventDefault();
                // event.stopPropagation();
        }, true);

Note that I have capture set to true. Maybe this has something to do with it.

Here is an example of the error: (there is a little red icon to the left of it with an exclamation point )


share|improve this question
It's possible that it can't be done at all. Why do you want to do this, what is your use case? –  Pekka 웃 Aug 25 '13 at 22:52
You can't catch & hide that error. It's a feature of the developer tools. –  Rob W Aug 25 '13 at 22:52
I could use try/throw/catch...that would work. –  Smurfette Aug 25 '13 at 22:55
A resource loading error is a network error, not a JavaScript error, and therefore cannot be caught by JavaScript. –  Niet the Dark Absol Aug 25 '13 at 22:56
@Smurfette: how would you do that for 404s? –  zerkms Aug 25 '13 at 22:56
add comment

1 Answer

up vote 1 down vote accepted

I think your error is part of the dev tools and not JavaScript natively. You can capture errors using window.onerror. This post goes into more detail on error capture.


share|improve this answer
The OP obviously understands event errors. However browsers behave differently after a capture. Some report the error in the console, some do not. –  mark_huffington Aug 26 '13 at 22:02
Thanks mark, this guy is new, so I'll mark it! –  Smurfette Aug 26 '13 at 23:29
add comment

Your Answer


