Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Verifying that a page has actually been loaded

    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Try this. Courtesy of Vladdy from this script. Modified a bit for this purpose.
    Code:
    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
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    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!

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by duma

    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •