Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
If image is not found on server, show alternative
Old 04-24-2006, 10:14 AM If image is not found on server, show alternative
amygdela's Avatar
Super Talker

Posts: 111
Trades: 0
Hi!

I'm looking for some help on a code. For a client I have to create a little script that searches for images on a webpage and if the image is not found, show an alternative one.

I think i can manage it in PHP, but since it's a .jsp page, I cannot use PHP! Can anybody point me in the right direction what to do here?


Any help is appreciated,

amygdela
__________________

Please login or register to view this content. Registration is FREE
amygdela is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-27-2006, 05:10 AM Re: If image is not found on server, show alternative
rck
Novice Talker

Posts: 7
Trades: 0
Actually, you might be able to do that by using CSS alone. For example using the Image Preloader technique. Instead of the animation mentioned there, you could go for a simple, gray graphics. That way, the graphics would prevail if the primary image is not available.
rck is offline
Reply With Quote
View Public Profile
 
Old 04-27-2006, 07:34 AM Re: If image is not found on server, show alternative
amygdela's Avatar
Super Talker

Posts: 111
Trades: 0
thanks, but I've found a js solution:

Code:
<html> 
<head> 
<script type="text/javascript"> 
  function fixBrokenImages(){ 
    // alle afbeeldingen uit tussen de body tags 
    var imglst = document.images; 
    for(var i = 0; i < imglst.length; i++){ 
      imglst[i].onerror = function() { 
        // weergeven als er een fout is opgetreden 
        this.src = "http://www.centcom.mil/_layouts/images/ERROR.GIF"; 
      } 
      // afbeelding refreshen omdat de onerror  
      // pas achteraf wordt ingesteld. 
      imglst[i].src = imglst[i].src; 
    } 
  } 
</script> 
</head> 
<body onload="fixBrokenImages();"> 
<img src="http://www.bonideproducts.com/images/checked.gif" /> 
<img src="http://www.bonideproducts.com/images/cheked.gif" /> <!-- FOUTIEVE URL --> 
<img src="http://www.bonideproducts.com/images/checked.gif" /> 
<img src="http://www.bonideproducts.com/images/checked.gif" /> 
</body> 
</html>

__________________

Please login or register to view this content. Registration is FREE
amygdela is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to If image is not found on server, show alternative
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.77209 seconds with 12 queries