Welcome to WebmasterWorld Guest from 23.20.137.66

Forum Moderators: incrediBILL

Message Too Old, No Replies

Replace red boxes

     
12:53 pm on Apr 17, 2008 (gmt 0)

10+ Year Member



Anyone got any ideas where i can find a script that if an image is unavaliable that it gets replaced with a default image?
2:29 pm on Apr 17, 2008 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi stevelibby,

There is an onError attribute that can be used to detect if the image doesn't load. I'm not sure how supported this is though!


<img src="link/to/image.gif" alt="Alt Text" onError="imageError(this)" />

<script type="text/javascript">
function imageError(element) {
element.style.border = '1px solid red';
}
</script>

In principle this should work, but I've not tested it!

HTH

[edited by: BlobFisk at 2:30 pm (utc) on April 17, 2008]

3:01 pm on Apr 17, 2008 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Just did a quick test and that's IE only.
3:07 pm on Apr 17, 2008 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You could use javascript from the body's onLoad event and loop through images, checking their size. If the image has no width or height (i.e. it never loaded), then change the src property of the image to the default one.
5:18 pm on Apr 17, 2008 (gmt 0)

5+ Year Member



Just did a quick test and that's IE only.

It works in FF too (and Opera, and Safari).
 

Featured Threads

Hot Threads This Week

Hot Threads This Month