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>
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>