: 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