View Full Version : On event not available do this

10-28-2003, 02:04 PM
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

10-28-2003, 02:16 PM
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 (http://www.codingforums.com/showthread.php?s=&threadid=19840)

<script type="text/javascript">
function setImg(newImg){
var obj=document.getElementById("dynImg");

<body onLoad="setImg('example01.jpg');">
<img id="dynImg" onError="this.src='noimageavail.jpg';">

Hope that helps,

10-28-2003, 02:32 PM
Thank you . Looking at the code it looks like it may do the job .
will look at Spookster's version too.


10-28-2003, 02:35 PM
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.