brokenImage: a jQuery plugin
brokenImage is a jQuery plugin that is able to detect and replace images that are either broken or are taking a long time to load. If no replacement image is specified then the CSS visibility is set to hidden.
Usage
Fix a broken Image
object:
var image = new Image(); image.src = '/might/be/broken.png'; image.brokenImage();
Fix a broken image tag:
<img src="https://github.com/might/be/broken.png" alt="Might be broken" id="myImage" /> $('#myImage').brokenImage();
Fix a collection of images:
<div id="myImages"> <img src="https://github.com/might/be/broken" alt="Might be broken" /> <img src="https://github.com/might/also/be/broken" alt="Might also be broken" /> </div> $('#myImages img').brokenImage();
Set a custom image replacement instead of setting the visibility to hidden:
image.brokenImage({replacement: '/images/placeholder.png'});
Set a custom timeout to override the 5 second default:
image.brokenImage({timeout: 100}); // 100 ms
Licensing
Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2011 Stateless Systems (http://statelesssystems.com)