472,955 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

repost: Redirection script

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
4 1995
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jerry | last post by:
Hi All I would very much appreciate your help: I have two scripts alternating in the background triggering themselves mutually. Here is how: 1.) Script A does something and then calls Script...
1
by: slash | last post by:
Hi, I have a page on my website that is driven dynamically off of a database by a perl/cgi script. The page contents are essentially reports of the following url:...
8
by: Manu | last post by:
Hi there, I am using a perl script to generate this html page which just redirects users to my ftp server. The problem is I get a "page cannot be displayed" in IE 6.0 (haven't tried other...
3
by: Wazz Up | last post by:
Hi, I'm trying run an image slide show where the images rotate once each, then after the last image in the array has been displayed for the specified amount of time, a redirection to another...
15
by: Taki Jeden | last post by:
Hello everybody Does anybody know why w3c validator can not get pages that use 404 htaccess redirection? I set up two web sites so that clients request non-existent urls, but htaccess redirects...
7
by: Steph | last post by:
Bonjour, Je souhaite lancer une redirection vers un fichier php via SRC= dans une condition if (voir ci-dessous en bas du script) mais la redirection ne fonctionne pas. Par contre la condition...
2
by: John Drako | last post by:
I have a database with a lot of links. Every so often I run a script to verify if the URLs are still valid. I weed out the ones with the 404 response. However, many responses are of the 303 kind...
1
by: comp.lang.php | last post by:
require_once("/users/ppowell/web/php_global_vars.php"); if ($_GET) { // INITIALIZE VARS $fileID = @fopen("$userPath/xml/redirect.xml", 'r'); $stuff = @fread($fileID,...
4
by: Neil Gould | last post by:
Anthony Jones wrote: That it is awaiting user action. Since a While/Wend or some other on-going background activity of a script appears to provide exceptions to the above statement, your usage...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.