It is not possible to get the status code directly in JavaScript without XMLHttpRequest. As pointed out, this is generally only same-domain although, there are two possible cross-domain approaches (not requiring a proxy server) to this I know of:
- Certain clients and servers willing to play can use Cross-Origin Resource Sharing and;
- There are also flash-based "XHR" solutions.
On the other hand, if all that is cared about is the image thought it could be loaded (which might not be a 200 at all!) it is possible to find this out using an Image element and the onload
event. If the onload
event doesn't fire in a certain amount of time it can be concluded the request timed out or failed (4xx/5xx). However, this will return a false-positive in case of 302, etc.
Just make sure the browser actually tries to load the Image: some of the more clever ones won't load hidden images, or so I've heard.
Happy coding.