Iframe check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theS70RM
    New Member
    • Jul 2007
    • 107

    Iframe check

    Hey,

    Ive got a compatability problem....

    Im trying to check when an Iframe is done loading...

    Can someone tell me why this doesnt work in Firefox but it does in IE:


    --------------------------------------------------------------------
    [HTML]<html>
    <head>
    <title>Check Statistics</title>

    <script type="text/javascript" language="JavaS cript"><!--
    function StateChanged(){
    var iframe = document.getEle mentById("stats ");
    alert("ready state change to: " + iframe.readySta te);

    if (iframe.readySt ate == "complete")
    {
    Done();
    }
    }

    function start(){
    var iframe = document.getEle mentById("stats ");
    iframe .setAttribute(" src","http://google.com");
    iframe .onreadystatech ange = StateChanged;
    }

    function Done(){
    alert("Done");
    }

    //-->
    </script>

    <body onload="start() ;">

    <a href="#" onclick="GetSta ts();">Get Statistics</a>

    <div>
    <iframe id="stats" width=720 height=500 src="" frameborder="ye s"
    scrolling="no"> </iframe>
    </div>
    </body>
    </html>
    [/HTML]-----------------------------------------------
    (didnt use code tags because then it pastes with the line numbers =(

    Cheers!


    Andy
    Last edited by acoder; Sep 12 '08, 04:55 PM. Reason: Added [code] tags
  • theS70RM
    New Member
    • Jul 2007
    • 107

    #2
    ok, so as soon as i set iframe.src = "whatever.html" ; then iframe.document should exist..... well it does in IE, but not in Firefox.

    Anybody know a way round this??

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by theS70RM
      (didnt use code tags because then it pastes with the line numbers =(
      Doesn't make them voluntary. You can click on reply to copy/paste without line numbers.

      Onto your question: use onload.

      Comment

      • theS70RM
        New Member
        • Jul 2007
        • 107

        #4
        hmm, do you mean use the onload property of the document that is to be loaded?

        I thought about that, I could edit the actual document to be loaded in the iframe and get it to call a function in the parent once it's loaded... I dont want to do that because it means editing every document I ever load in there, some I will not be able to as they are external.

        If you're talking about something like this:


        Code:
        myiframe = document.createElement("iframe");
        myiframe.src = "myurl/mypage.php";
        myiframe.document.body.onload = function(){ alert("ive loaded!"); }

        then it still does me no good, I cant access the document property in this way until the page has actually loaded.. that's the whole problem.

        Any other ideas???


        Cheers


        Andy

        ps. note the expert use of code tags =P

        Comment

        • theS70RM
          New Member
          • Jul 2007
          • 107

          #5
          it doesnt seem right to me, can someone test the above code in firefox please :-\

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            I meant something like myiframe.onload . See if that works.

            Comment

            • theS70RM
              New Member
              • Jul 2007
              • 107

              #7
              hmmm, well that does get called when the iframe has been loaded. But i think that's seperate from the contained document's onload function.

              My ultimate aim is simply to get the height of the contained document so I can ammend the iframes height to suit.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Use the contentDocument to get the document contained within the iframe.

                Comment

                • theS70RM
                  New Member
                  • Jul 2007
                  • 107

                  #9
                  aha, that's what I've been missing.


                  I've never used that property before but it seems to do the trick nicely.


                  Thanks very much!


                  Andy

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Glad it worked :)

                    Comment

                    Working...