Javascript Detect Broken Image
Posted by tech on
May 26, 2008
We have no way to know if an image is broken or not especially if we are just hot linking it from some other site. Javascript’s onerror function just does that. To add a no-image-file as replacement instead of the broken image icon (which would make your site look unprofessional), use this function below.
1 2 3 4 5 6 | function onImgError(source) { source.src = "no-image-125px.gif"; // disable onerror to prevent endless loop source.onerror = ""; return true; } |
and call it using this <img src="test.gif" onerror="onImgError(this)"/>
tip from: http://www.tech-evangelist.com/2007/09/15/missing-image-fix/








November 17th, 2009 at 6:11 pm
nice, didn’t know that existed. its built into jquery now = sweet
November 17th, 2009 at 6:23 pm
cool! that’s great news!