By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,995 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,995 IT Pros & Developers. It's quick & easy.

repost: Redirection script

P: n/a
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?

Feb 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I didn't have a clue till I read these

http://www.codingforums.com/showthread.php?t=59907
http://talideon.com/weblog/2005/02/d...-images-js.cfm

Their answer is to check the naturalWidth (found only in moz/firefox I
think) property of an image, if its non zero then image is ok. Assume
failure with all other values

Feb 20 '06 #2

P: n/a
Hiya

Wasnt sure about this one and found the links below useful. They both
had a simlar problem, their solution would be check for a nonzero value
in either the width or naturalWidth properties of the image within the
onload function.

Hope these help...
http://javascript.about.com/library/blfailimg.htm
http://www.codingforums.com/showthread.php?t=59907

Feb 20 '06 #3

P: n/a
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
}

Feb 20 '06 #4

P: n/a
pdc
You are a god!!

Thanks so much for that, it really helps.

cheers.
PDC
"tihu" <ti********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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
}

Feb 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.