views:

24

answers:

1

In most cases you can replace a broken image with some code that looks like this:

<img src="image.jpg" onerror="this.onerror=null;this.src='default.jpg'">

However, it doesn't seem to work with broken twitter profile images like this:

http://a1.twimg.com/profile_images/52087244/Photo_26.jpg

Is this because it is returning 403 instead of 404? Is there any way to fix this?

+1  A: 

If onerror isn't working, you could try attaching a function to onload which does some checks to see if the image is acceptable (maybe testing width/height/src) and tries another if that doesn't work...

Weston C
Interesting approach. You mean check if width=0, height=0, etc.? Seems like it might work, but I was hoping for something a little more elegant.
Joe
I'd guess it'd be better to test `typeof img.width == 'number'`, rather than 0, but yes, something like that.
Weston C