I can detect server status in JS but have a bug....

R

Remy Sharp

Hi,

I've successfully written code that will check a primary server then a
backup server if the primary is down and then displays an iframe/layer
to that server. If both are down, then the iframe is not loaded and
kept hidden.

I have included the code below. However, I have a bug: when the
iframe is loaded it takes over the entire window - which is not the
effect I want.

This code works in IE5-6, NS4.6-7, Opera, etc. Sometimes in IE it can
load the content within the original window, however, a simple refresh
looses the rest of my content.

To test the fail over in the code, change the image url that it tries
to load.

Here is the example code:

================ CODE ==================
<html>
<body>

This the beginning of my document, but when my iframe loads this
window will
be loaded with different content.

<script language="JavaScript1.1">

var pageid="3010";
var fheight="400";
var fwidth="640";

var rnd = (Math.random().toString()).substring(2);
var img = new Image();
img.onload = loadHandler;
img.onerror = errorHandler;
img.src = 'http://www.google.com/images/logo.gif';

function errorHandler () {
if (img.src.indexOf('google.com') != -1)
img.src = 'http://www.google.co.uk/images/logo.gif';
}

function loadHandler () {

if (img.src.indexOf('google.com') != -1)
{
var s1='<iframe width=' + fwidth + 'px height=' + fheight +
'px src="http://www.google.com" marginheight=0 marginwidth=0 border=0
frameborder=0 scrolling=no name=ifmainnav></iframe>';
var s2='<layer width=' + fwidth + 'px height=' + fheight + 'px
src="http://www.google.com"></layer>';

if (!document.all)
document.open();

document.write(s1);
document.write(s2);

if (!document.all)
document.close();
}
else
{
if (img.src.indexOf('google.co.uk') != -1)
{
var s1 = '<iframe width=' + fwidth + ' height=' + fheight
+ ' src="http://www.google.co.uk" marginheight=0 marginwidth=0
border=0 frameborder=0 scrolling=no name=ifmainnav></iframe>';
var s2 = '<layer width=' + fwidth + ' height=' + fheight +
' src="http://www.google.co.uk"></layer>';

if (!document.all)
document.open();

document.write(s1);
document.write(s2);

if (!document.all)
document.close();
}
}
}

</script>
</body>
</html>
 

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,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top