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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.