404 Image Detection Using Javascript

My app has links to photos on Twitter.

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

I use Img methods onloadand onerrorjavascript, but since p.twimg.com returns the body, the method starts onload. I did not find a way to distinguish 404 from 200.

Any idea?

+5
source share
1 answer

Check the image size if it is 6.232 bytes (the image size was not found on Twitter) or not.

To find the image file size

+3
source

All Articles