PDA

View Full Version : Need an alternate page to load in IFrame as backup



zmurtaza
Apr 5th, 2007, 02:05 AM
Hi,

I originally posted this issue in HTML section but I was told that this could be acheived with Javascript.

I have setup an IFrame and it is currently working. I need to specify an alternate page to load in the same frame if the main page that loads in the frame is unavailabe.

eg. main_page.html is loading in the IFrame window. If main_page.html is not available, then I would like backup_page.html to load in its place.

I know almost nothing abount Javascript, but this is what I have come up with so far:

--------------------------------------------------------------------------
var Mpage = 'http://www.exampledomain.com/main_page.html';
var Bpage = 'http://www.anotherdomain.com/backup_page.html';
var LoadPage = ??????????;


document.write('<center>');
document.write('<iframe src="'+LoadPage+'" name="I2" height="730" width="511" border="0" frameborder="0">');
document.write('Your browser does not support inline frames or is currently configured not to display inline frames.')
document.write('</iframe>');
document.write('</center>');
--------------------------------------------------------------------------

I don't know how to complete the script to determine the 'LoadPage' variable. Actually, I don't even know if I am on the right track :confused:

This is probably a simple thing to do, but unfortunately I don't know how.

I would appreciate any and all help.

Thanks.

antimatter15
Apr 5th, 2007, 07:11 PM
I don't know if this will work but,

var Mpage = 'http://www.exampledomain.com/main_page.html';
var Bpage = 'http://www.anotherdomain.com/backup_page.html';
var LoadPage = "";
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();
}
catch(e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Your browser does not support XMLHTTPRequest");
return false;
}}}
xmlHttp.open( "GET", Mpage);
setTimeout("next();",1000);
if (xmlHttp.status != 404){
LoadPage = Mpage;
}else{
LoadPage = Bpage;
}
document.write('<center>');
document.write('<iframe src="'+LoadPage+'" name="I2" height="730" width="511" border="0" frameborder="0">');
document.write('Your browser does not support inline frames or is currently configured not to display inline frames.')
document.write('</iframe>');
document.write('</center>');