Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect 404 images using Javascript

I have in my application some references to Twitter photos.

When the photo is no longer available on Twitter side (see this example: http://p.twimg.com/AmL3hpaCEAd2wtN.jpg), I receive a 404 response code with an image as a body (the gray 404 image)

I'm using onload and onerror javascript methods on Img, but since p.twimg.com is returning a body, the onload method is triggered. I found no way to distinguish a 404 response from a 200 one.

Any idea?

like image 801
Chris Avatar asked Oct 23 '22 19:10

Chris


1 Answers

Check image size if it's 6.232bytes(Twitter not found image's size) or not.

To find image file size

like image 147
totten Avatar answered Oct 27 '22 09:10

totten