...

View Full Version : Verifying that a page has actually been loaded



duma
06-14-2004, 03:22 PM
Hi!

I've been trying to make a script which reloads a page every 1 min (let's call it page_ok). If the page cannot be loaded (I.e. the Internet connection has been lost) a local default page should be loaded (page_error). The script will continue to try to reload the page_ok every 1 min.

I have tried this with frames and iframes, but my problem is that I cannot find a method/property to check whether page_ok has actually been loaded successfully. The iframe.src property contains the link to page_ok even though I get a DNS error page not found.

Is there anyway to make the check?

PS. The browser is IE 5.5+

Any help is highly appreciated :)

glenngv
06-15-2004, 12:50 PM
Try this. Courtesy of Vladdy from this script (http://www.codingforums.com/showthread.php?t=30449). Modified a bit for this purpose.


function getFile(filename)
{
var oxmlhttp = null;
try
{
oxmlhttp = new ActiveXObject("Msxml2.oxmlhttp");
}
catch(e)
{
try
{
oxmlhttp = new oxmlhttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e)
{
return -1;
}
}
if(!oxmlhttp) return -1;
try
{
oxmlhttp.open("HEAD",filename,false);
oxmlhttp.send(null);
}
catch(e)
{
return -1;
}
return oxmlhttp.status;
}

var theFile = "http://mydomain.com/page_ok.htm";
function pollFile(){
switch (getFile(theFile)){
case 200:
top.frames['theIframeName'].location.href = theFile; //OK
break;
case 404:
top.frames['theIframeName'].location.href = "404.htm"; //file not found page
break;
case 500:
top.frames['theIframeName'].location.href = "500.htm"; //page cannot be displayed page
break;
default:
top.frames['theIframeName'].location.href = "error.htm"; //generic error page
}
}

setInterval("pollFile()", 60000); //poll the file every 1 minute

duma
06-15-2004, 02:54 PM
Thanks for the help!

However, I had to make a small change in the code to make it work.

In line 6:

oxmlhttp = new ActiveXObject("Msxml2.oxmlhttp");

had to be changed to:

oxmlhttp = new ActiveXObject("Msxml2.xmlhttp");

I don't know whether it was a typo - I'm not that good with Jscript :)

Secondly, I needed to change the sequrity settings in IE to allow the browser to access data sources across domains to get rid of a security pop-up.

Cheers!

glenngv
06-16-2004, 06:12 AM
However, I had to make a small change in the code to make it work.

In line 6:

oxmlhttp = new ActiveXObject("Msxml2.oxmlhttp");

had to be changed to:

oxmlhttp = new ActiveXObject("Msxml2.xmlhttp");

I don't know whether it was a typo - I'm not that good with Jscript :)

Sorry, that was the result of the "Find-Replace All" I did.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum