homepage Welcome to WebmasterWorld Guest from 107.21.187.131
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

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

HTML Forum

    
Replace red boxes
stevelibby




msg:3629045
 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




msg:3629125
 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




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

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

vincevincevince




msg:3629159
 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




msg:3629281
 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