homepage Welcome to WebmasterWorld Guest from 54.166.62.226
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Replace red boxes
stevelibby

10+ Year Member



 
Msg#: 3629043 posted 12:53 pm on Apr 17, 2008 (gmt 0)

Anyone got any ideas where i can find a script that if an image is unavaliable that it gets replaced with a default image?

 

BlobFisk

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



 
Msg#: 3629043 posted 2:29 pm on Apr 17, 2008 (gmt 0)

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]

BlobFisk

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



 
Msg#: 3629043 posted 3:01 pm on Apr 17, 2008 (gmt 0)

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

vincevincevince

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



 
Msg#: 3629043 posted 3:07 pm on Apr 17, 2008 (gmt 0)

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.

Achernar

5+ Year Member



 
Msg#: 3629043 posted 5:18 pm on Apr 17, 2008 (gmt 0)

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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved