PDA

View Full Version : Check if server is online (checks to see if image exists)


sosuke
12-01-2004, 07:30 PM
<html>
<head>
<title>Restart</title>
<script>
var i = 1;
var msgarray = new Array();
msgarray[0] = ".";
msgarray[1] = "..";
msgarray[2] = "...";
msgarray[3] = "....";
msgarray[4] = ".....";
function setText() {
document.getElementById('msgtxt').innerHTML = msgarray[i];
i=i+1;
if(i==5) { i=0; }
testImage("../images/logo.jpg");
}

function testImage(URL) {
var tester=new Image();
tester.onload=load;
tester.onerror=setText;
tester.src=URL;
}

function load() {
top.centerFrame.canvas.location="../htmls/splash.htm";
}

window.setInterval('testImage("../images/logo.jpg")', 1000);
</script>
</head>
<body>
<table width="100%" height="95%" align="center" valign="middle">
<tr>
<td width="50%" height="100%" align="right" valign="middle">
<h3>Please Wait</h3>
</td>
<td width="50%" height="100%" align="left" valign="middle">
<h3 id="msgtxt">.</h3>
</td>
</tr>
</table>
</body>
</html>


Simple enough, checks to see if the image is accessible, I used it to check to see if my server had restarted yet, modify as you wish! Be careful changing it thought its VERY finiky!

Thanks to Willy Duitt and glenngv for the assist!

ArcticFox
12-09-2004, 04:15 AM
Whatever happend to stuffing the IMG tag with the onError JS event?

Am I getting old? Is this stuff still around? :D

Great script, though!

mindlessLemming
12-15-2004, 06:19 AM
This script could also be used to discover whether users have images disabled -- very helpful if you use CSS image replacement techniques :)

jbot
12-22-2004, 12:20 PM
This script could also be used to discover whether users have images disabled -- very helpful if you use CSS image replacement techniques

doubt it. users who have images disabled are probably also likely to have JS disabled, in which case nothing would work.

Bolter99
02-12-2005, 06:52 AM
could just use:

<img src="../images/logo.jpg" style="width:0;height:0;visiblity:hidden;position:absolute;" onload="functiona()" onerror="functionb()">

Meh... its easy that way...

codegoboom
02-12-2005, 10:31 AM
IE allows for checking directly (window.navigator.onLine), unless I'm thinking of something completely different... ;)

Gary King
03-29-2005, 04:35 AM
Could someone possibly explain the parts that require changing and what they are for? :thumbsup:

Gary King
03-29-2005, 04:46 AM
I tried setting top.centerFrame.canvas.location="../htmls/splash.htm"; to a full URL but it gives me JS errors now. Help?