HTML & WEB-Design

Moderators: Jonathan
Number of threads: 1253
Number of posts: 3360

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
Alternate images, can this be done with plain HTML? Posted by Shadow on 14 Feb 2001 at 10:45 AM
I'd like a page to display an image(image1.jpg), but it will be on a server that is not always online, so I would like to know if there's a way to make it display another image(image2.jpg) if the first one is not there, kinda like an "Online/Offline" thing...
The best thing working now is <img src="image1.jpg" alt="Server offline">... but I want it to show an image, not text...

Does anyone know how to do this? Even if it's in php or something else I can use it... but I would prefer plain HTML if it's possible.

Edit Report
Re: Alternate images, can this be done with plain HTML? Posted by iDaZe on 14 Feb 2001 at 2:09 PM
: I'd like a page to display an image(image1.jpg), but it will be on a server that is not always online, so I would like to know if there's a way to make it display another image(image2.jpg) if the first one is not there, kinda like an "Online/Offline" thing...
: The best thing working now is <img src="image1.jpg" alt="Server offline">... but I want it to show an image, not text...
:
: Does anyone know how to do this? Even if it's in php or something else I can use it... but I would prefer plain HTML if it's possible.
:

I don't think that it's possible in plain HTML, but I worked something out in php:

<?php
if (@fopen('http://myserver/image1.jpg', 'r') == false) {
echo "<img src='http://backupserver/image2.jpg'>";
} else {
echo "<img src='http://myserver/image1.jpg'>";
}
?>

now that I think about it, it may also be possible with JavaScript, don't know the code yet, but you could try to preload the first image, and if that returns null, preload the second one ... I think something like (this may not be completely syntacticly correct):

myimg = new image()
myimg.src = 'http://myserver/image1.jpg'
if (myimg.src = null) {
myimg.src = 'http://backupserver/image2.jpg'
}


and then something like
<img src=myimg.src>

good luck

Edit Report
doh, stupid autolinking Posted by iDaZe on 14 Feb 2001 at 2:13 PM
http://myserver/image1.jpg
should be

h t t p : / / m y s e r v e r / i m a g e 1 . j p g

without the spaces




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.