Friday, March 30, 2012

Broken Image?

Recently I found a really cool way to handle "broken images". This happens all the time when you have a some sort of auto-generated image, or an expected image but then sometimes the file doesn't exist, or something happened to it. Here is one fairly cheap way to set up a default image:

http://stackoverflow.com/questions/717734/best-way-to-display-default-image-if-specified-image-file-is-not-found


In other words, something like this:
<img src="image.jpg" onerror="this.onerror=null;this.src='default.jpg'">

So far I've tested in ie9, chrome, and firefox and works in all three. Pretty cool!