homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Show a picture when another picture doens't load

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


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).




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

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. :)


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

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.



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

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)


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

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.


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

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

function down(e) {
e.src='url of image replacement';
<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)">

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
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