Posted By

FatFolderDesigner on 01/08/12


Tagged

javascript images ErrorHandling


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

Balamir
tibo77
BrockSamsom
Priestd09


Auto-Replace Broken Images


 / Published in: jQuery
 

URL: http://fatfolderdesign.com/525/code/auto-replace-broken-images

There are 2 jQuery snippets, both replace broken images with one of your choosing, the difference is that one is "safe" and the other is "persistent". The safe one will quick working, so if your doing something that dynamically changed images on a page it'll only work for the first broken image. The persistent one will keep working, but if your missing image image is missing it'll cause a overflow error.

  1. // Safe Snippet
  2. $("img").error(function () {
  3. $(this).unbind("error").attr("src", "missing_image.gif");
  4. });
  5.  
  6. // Persistent Snipper
  7. $("img").error(function () {
  8. $(this).attr("src", "missing_image.gif");
  9. });

Report this snippet  

You need to login to post a comment.