Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Show a picture when another picture doens't load

     

turbohost

7:11 pm on May 30, 2007 (gmt 0)

10+ Year Member



Hi,

Is it possible to show another picture if a picture doesn't load on your site? E.g. I show picture A from website A on my website (ok, ok, it's hotlinking :-) ). If picture A doesn't load, I want to show picture B (and no alternative text).

Turbo

encyclo

4:59 pm on May 31, 2007 (gmt 0)

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



It isn't possible with HTML as such, but it may well be possible using mod_rewrite (assuming your server is running Apache) to rewrite non-existent image URLs to a specific file. It is similar in many ways to an anti-hotlinking script, but the conditions for the rewrite would be different.

I'm moving this thread over to our Apache forum to see if you can get a more definitive answer from the rewrite experts. :)

jdMorgan

12:22 am on Jun 1, 2007 (gmt 0)

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



You'd have to 'wrap' the image in a script, use the script to GET the image, and then substitute something else if the GET was unsuccessful. Of course, this means that all image requests would come from your server instead of the client, making it trivially easy to track you down...

Doing this to grab images from any site I administrate wouldn't work, at least not for long...

With respect, I'd suggest finding a better way to do business.

Jim

Achernar

12:23 am on Jun 1, 2007 (gmt 0)

5+ Year Member



You can do it with javascript.

How many images do you have to check on a single page? Are they always the same one?
Are you pages dynamic or static? (.asp/.php vs .html)

turbohost

10:01 am on Jun 2, 2007 (gmt 0)

10+ Year Member



Hi Guys and thanks for all the responses. I think I have to elaborate a little bit more. The images are always the same image (i.e. a green bullet) and I provide this image to the other webmasters. The other webmasters agree to put this image in the home directory of their website. I open their image via img src on my webpage. If their image doesn't load it means that their website is down or filtered. If the site is down I want to show another image instead of the alternate text.

Achernar

12:28 pm on Jun 3, 2007 (gmt 0)

5+ Year Member



A simple solution (if the replacement image is always the same) could look like this:

<html> 
<script>
function down(e) {
e.src='url of image replacement';
}
</script>
<body>
<img src="http://none.dev.null/image.gif" onerror="down(this)">
<img src="http://another.dev.null/image.gif" onerror="down(this)">
<img src="http://last.dev.null/image.gif" onerror="down(this)">
</body>
</html>
 

Featured Threads

Hot Threads This Week

Hot Threads This Month