1

... 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 )

Failed to load resource: the server responded with a status of 404 (Not Found)

5
  • 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, 2013 at 22:52
  • 1
    You can't catch & hide that error. It's a feature of the developer tools.
    – Rob W
    Aug 25, 2013 at 22:52
  • I could use try/throw/catch...that would work.
    – Smurfette
    Aug 25, 2013 at 22:55
  • 1
    A resource loading error is a network error, not a JavaScript error, and therefore cannot be caught by JavaScript. Aug 25, 2013 at 22:56
  • 1
    @Smurfette: how would you do that for 404s?
    – zerkms
    Aug 25, 2013 at 22:56

1 Answer 1

1

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.

http://mattsnider.com/window-onerror-event/

1
  • 1
    The OP obviously understands event errors. However browsers behave differently after a capture. Some report the error in the console, some do not. Aug 26, 2013 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.