Entry
Why are browser errors like a 404 not caught by window.onerror?
Why are browser errors like a 404 not caught by window.onerror?
Apr 23rd, 2000 08:57
Mike Hall, Martin Honnen, Elsa,
If you define your own client side JavaScript
window.onerror
handler (as described in
http://www.faqts.com/knowledge-base/view.phtml/aid/1067/fid/145
) you will find that browser errors (like a 404 (page not found) when
you set location.href to attempt to load a new page) are not caught by
your error handler. Unfortunately Netscape decided not to expose such
errors (they call them browser errors in contrast to pure JavaScript
errors) to the window.onerror handler and MS with IE followed that way.
So there is currently no way to generally handle such errors in client
side JavaScript.
If you want to check whether a web (http) server is reachable you can
in restricted cases do so using the Image object. See
http://www.faqts.com/knowledge-base/view.phtml/aid/1799/fid/122/lang/en
for details.
Just as a clarification, HTTP 404 (and others) are response errors sent
by the web server. They do not necessarily reflect an error on the
browser's part but rather on the server (e.g. page not found or server
too busy). Many web servers provide for default or customized error
pages to be sent in place of the error code so they often in fact return
a perfectly valid document to the browser.