Auto-Replace Broken Images


/ Published in: jQuery

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.


Copy this code and paste it in your HTML
  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. });

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.