repost: Redirection script

P

pdc

have two web servers that I use, one is the primary and the other is a
backup for when the server is down.
I use a third, central server which redirects a browser's initial link to
one of my web servers.
Rather than getting involved with CGI to determine the status of the web
servers, I found and implemented the following javascript.

<!- this is a very simple page that uses javascript to detect
whether or not a gif file can be obtained from a system's
web server.
If the gif file cannot be found, either because the system
is down or the webserver is inactive, then the imageError
function redirects the browser to a backup server.
-->
<head>
<title>PDC's start</title>
<SCRIPT LANGUAGE = "JavaScript">
<!--
function imageError()
{
top.location = "http://webserver2/home.html";
}
function imageLoad()
{
top.location = "http://webserver1/home.html";
}
var imgTest = new Image();
imgTest.onerror = imageError;
imgTest.onload = imageLoad;
imgTest.src =
"http://webserver1/ThisGIFimageControlsWhichWebServerisChosen.gif";
-->
</SCRIPT>
<HTML>

IE. the redirection proceeds as required. Trouble is, I don't want to use
IE.

Using Firefox (1.5.0.1) -- it's enabled for javascript --
What I notice is that it is only partially successful in doing what I want.
If I rename the gif file, for example, the redirect works well and
webserver2 is chosen.
But if webserver1 or the machine that webserver1 runs on is down, then the
initial request fails, still trying to access webserver1/home.html
Is this WAD, or is there anything I can tweak to ensure that when webserver1
is unavailable then webserver2 is accessed?
 
T

tihu

Correction: naturalWidth will always be undefined in IE, only firefox
sets it to a non zero value

What you need in your imageLoad function to handle the firefox bug
is.....( from the talideon link )

if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
// img didnt load and user needs be redirected
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top