Click to See Complete Forum and Search --> : How to check if another site is up for redirecting?
reijndert
08-09-2003, 06:10 AM
I'm looking for a way to dynamically put
"site X is UP or DOWN" on my webpage.
I run a webserver on one machine and a forum on another machine. The 2nd machine is down sometime and I want a "FORUM DOWN" statement so no-one can use the link to access the forum if it's down.
My site: http://reijndert.homelinux.com
How do I accomplish this (simple?) task.
-reijndert.
Charles
08-09-2003, 06:33 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
ping = new Image();
ping.onerror = function () {document.getElementById('ping').replaceChild(document.createTextNode('Server is off line'), document.getElementById('ping').firstChild)}
ping.onload = function() {document.getElementById('ping').replaceChild(document.createTextNode('Server is on line'), document.getElementById('ping').firstChild)}
window.onload = function () {ping.src = 'http://forums.webdeveloper.com/img/webdevlogoz.gif'};
// -->
</script>
<p id="ping">&nbsp;</p>
The idea is to use the "onload" and "onerror" handlers of an Image object and some image on that server.
reijndert
08-09-2003, 07:31 AM
Good idea!
I tried this, but nothing happens. I'm no JS guru, sorry.
The GIF exists on the server. My router uses Port forwarding; therfore the :8000
Any clue?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Example</title>
<script type="text/javascript">
<!--
ping = new Image();
ping.onerror = function () {document.getElementById('ping').replaceChild(document.createTextNode('Server is off line'), document.getElementById('ping').firstChild)}
ping.onload = function() {document.getElementById('ping').replaceChild(document.createTextNode('Server is on line'), document.getElementById('ping').firstChild)}
window.onload = function () {ping.src = 'http://reijndert.homelinux.com:8000/cgi-bin/checkimage.gif'};
// -->
</script>
</head>
<body>
Hello world!<br>
Server status:
<p id="ping"> </p>
</body>
</html>
Charles
08-09-2003, 07:59 AM
It seems to work for me, except for the invalid HTML and the fact that 13% of the time this will not work, leaving your "Server Status" message hanging there, doing nothing.