Alternate images, can this be done with plain HTML? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Alternate images, can this be done with plain HTML?

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

Comments

  • : 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 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 "image";
    }
    ?>

    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
    image

    good luck

  • 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 :-D

Sign In or Register to comment.