Detecting a image 404 in javascript.

Posted by xal on Stack Overflow See other posts from Stack Overflow or by xal
Published on 2010-06-10T22:44:31Z Indexed on 2010/06/10 22:52 UTC
Read the original article Hit count: 387

After a user uploads a file we have to do some additional processing with the images such as resizing and upload to S3. This can take up to 10 extra seconds. Obviously we do this in a background. However, we want to show the user the result page immediately and simply show spinners in place until the images arrive in their permanent home on s3.

I'm looking for a way to detect that a certain image failed to load correctly (404) in a cross browser way. If that happens, we want to use JS to show a spinner in it's place and reload the image every few seconds until it can be successfully loaded from s3.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery