Click to See Complete Forum and Search --> : Alternate Images


TKNick
04-11-2003, 10:45 PM
I posted this on the HTML section and I was told I'd have a better chance to do it in JS.
I don't have any experience in any languages other than HTML. But I need a script that displays an image, if it can't (404, red x, ect), it displays a different image. I mainly want to do this to show the status of my game server.

Thanks for any help.

khalidali63
04-12-2003, 12:55 AM
javascript itself doesn't really have the ability to find out that if a server is up and a resoure is available on it.
Better solution is using some sort of werver side programming languge to determine that or mauy be look at this link.its a hack it can be used to find out if a server is up or not.

http://68.145.35.86/skills/javascripts/FindOutAServerIsUp.html

Cheers

Khalid

TKNick
04-12-2003, 01:24 AM
I'm not sure if I set it up right, which I probably didn't. Anyway, this is what I tried to do, but it didn't display any image where the server was on or offline:

<script type="test/javascript">
var errorIndex = new Array();
function loadHandler (evt) {
if (this.src.indexOf('resources') != -1){
location.href = '../JavaScriptResourcePage.html';
}
}

function errorHandler (evt) {
if (this.src.indexOf('resources') != -1){
img.src ='http://cywh.com/sites/wahonline/images/RedLight.gif;

}
}

var img = new Image();

img.onload = loadHandler;
img.onerror = errorHandler;
img.src ='ftp://guest:guest@ftp.saoghal.dynu.com/GreenLigh.gif';
//server actually have an image flake.gif therefore changing
//the spelling above will load the resource page.
</script>


Thanks for the help.

TKNick
04-12-2003, 05:33 AM
Heh, don't worry about it. I'm cheating :). I took the image that shows when an image cannot be displayed (the little red X) and I edited it, so it showed a green check :) I made it so it just displayed that green check, and if the server is offline, it shows the red X, which is a same-style box:
If my server is online, it will show it: ftp://guest:guest@ftp.saoghal.dynu.com/Online.GIF.