Chris
Chris

Reputation: 2800

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?

Upvotes: 5

Views: 2108

Answers (1)

totten
totten

Reputation: 2817

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

To find image file size

Upvotes: 3

Related Questions