Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    On event not available do this

    I would like help on how to do the following in JS.

    On load get image.gif from http://abc.com
    If image.gif from http://abc.com is not available
    Then goto http://xyz.com and get image.gif

    What I'm trying to do is have my online presence known http://abc.com is my webserver @ home
    http://xyz.com is a hosted server @ yahoo

    I am sorry if I may not be sticking to the guidelines, This just seemed the best way to explain.

    Thank you

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    241
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Halu and welcome aboard!

    Yes, there is a solution to your problem, in fact I think your description was very well put.



    Take a look at this code, written by Danne [or choose Spookster's version if you find it more attractive] in this thread

    Code:
    <script type="text/javascript">
    function setImg(newImg){
        var obj=document.getElementById("dynImg");
        obj.src=newImg;
    }
    
    </script>
    <body onLoad="setImg('example01.jpg');">
    ...
    <img id="dynImg" onError="this.src='noimageavail.jpg';">
    Hope that helps,

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you . Looking at the code it looks like it may do the job .
    will look at Spookster's version too.


  • #4
    Regular Coder
    Join Date
    Mar 2003
    Posts
    241
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's just beneath Danne's in the link I posted.

    Personally I would have used Spookster's version as it does not mess with the onload-event. IMO it's a good practice to avoid doing so unless you really have to.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •