iFrames Page load

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adnanx82@gmail.com

    iFrames Page load

    Hi,

    I was wondering if anyone knew how to perform the following 2 tasks in
    Javascript:

    1) distinguish between frames and iframes (during an onload event for
    example)
    2) figure out whether a container page has finished loading completely
    with all its component frames or iframes (onload event is not useful
    because we have more than one onload, and container page onload is not
    always the last one for iframes).

    Thanks,

    -Adnan.

  • kaeli

    #2
    Re: iFrames Page load

    In article <1115071239.246 929.71140@f14g2 000cwb.googlegr oups.com>, adnanx82
    @gmail.com enlightened us with...[color=blue]
    > Hi,
    >
    > I was wondering if anyone knew how to perform the following 2 tasks in
    > Javascript:
    >
    > 1) distinguish between frames and iframes (during an onload event for
    > example)[/color]

    Depends.
    Checking from where, the window itself or a containing window?
    Generally, you can't tell, but you might be able to fudge it by checking
    getElementsByTa gName and putzing around.
    [color=blue]
    > 2) figure out whether a container page has finished loading completely
    > with all its component frames or iframes (onload event is not useful
    > because we have more than one onload, and container page onload is not
    > always the last one for iframes).[/color]

    I can't think of a way, other than having every child and the container set
    variables when they load, then checking those variables.
    A hack, basically. Not pretty.

    --
    --
    ~kaeli~
    Practice safe eating - always use condiments.



    Comment

    • Jerome Bei

      #3
      Re: iFrames Page load

      >>2) figure out whether a container page has finished loading completely[color=blue][color=green]
      >>with all its component frames or iframes (onload event is not useful
      >>because we have more than one onload, and container page onload is not
      >>always the last one for iframes).[/color]
      >
      >
      > I can't think of a way, other than having every child and the container set
      > variables when they load, then checking those variables.
      > A hack, basically. Not pretty.
      >[/color]

      I don't know if this works for Mozilla or Opera, but using IE, you could
      check the readyState of the (i)frames contained in your main window:

      <html>
      <head>
      <script>
      Globals={
      checkReadyState :function() {
      for (var f=0; f<document.fram es.length; f++) {
      frame = document.frames (f);
      while (frame.document .readyState!="c omplete") {
      status+="."; // just wait ...
      }
      }
      }
      };
      </script>
      </head>
      <body onload="Globals .checkReadyStat e();">
      <iframe src="test.html" >
      <iframe src="test.html" >
      <iframe src="test.html" >
      <iframe src="test.html" >
      </body>
      </html>

      Comment

      • Csaba Gabor

        #4
        Re: iFrames Page load

        adnanx82@gmail. com wrote:[color=blue]
        > 1) distinguish between frames and iframes (during an onload event for
        > example)[/color]

        Unclear what the reference point is on this, but if the i/framed window
        is wondering (and it's not a cross domain situation), what about:
        window.frameEle ment.nodeName
        [color=blue]
        > 2) figure out whether a container page has finished loading completely
        > with all its component frames or iframes (onload event is not useful
        > because we have more than one onload, and container page onload is not
        > always the last one for iframes).[/color]

        One approach is to have a variable at the top level which each loaded
        frame increments (in its onLoad routine). When all frames have
        loaded, then the variable's value will equal the number of i/frames
        (which each onLoad routine is, of course, checking for. In that
        event, the top.everybodyLo aded routine can kick off). The post below
        illustrates this for the two i/frame case (the variant at the bottom
        is closer to what I'm talking about here).


        Good luck,
        Csaba Gabor from Vienna.

        Comment

        • Csaba Gabor

          #5
          Re: iFrames Page load

          Csaba Gabor wrote:[color=blue]
          > adnanx82@gmail. com wrote:[color=green]
          >> 2) figure out whether a container page has finished loading completely
          >> with all its component frames or iframes (onload event is not useful
          >> because we have more than one onload, and container page onload is not
          >> always the last one for iframes).[/color]
          >
          > One approach is to have a variable at the top level which each loaded
          > frame increments (in its onLoad routine). When all frames have
          > loaded, then the variable's value will equal the number of i/frames
          > (which each onLoad routine is, of course, checking for. In that
          > event, the top.everybodyLo aded routine can kick off). The post below
          > illustrates this for the two i/frame case (the variant at the bottom
          > is closer to what I'm talking about here).
          > http://groups-beta.google.com/group/...71708cb459e632[/color]

          Here's a concrete example that I put together on FF 1.0 / IE 6
          that checks whether all the frames are loaded (but not for the
          container page being loaded).

          <html><head><ti tle>Multiload Test</title>
          <script type='text/javascript'>
          loadCount = 0;
          function everybodyLoaded () {
          alert("Number of frames loaded: " +
          window.frames.l ength); }
          </script>
          </head><body>
          <iframe src="javascript :'<body onload=&quot;
          alert(&amp;#34; I\&#39;m a/n &amp;#34;+
          window.frameEle ment.tagName);
          if (++parent.loadC ount==
          parent.frames.l ength) parent.setTimeo ut(parent.
          everybodyLoaded ,0)&quot;>Frame 1</body>'">
          </iframe>
          <iframe src="javascript :'<body onload=&quot;
          if (++parent.loadC ount==
          parent.frames.l ength) parent.setTimeo ut(parent.
          everybodyLoaded ,0)&quot;>Frame 2</body>'">
          </iframe>
          </body>
          <html>


          Also, it is (I think) instructive to see what happens
          if you replace the two lines starting with 'alert' in
          the main body (in other words, lines 10 and 11) with
          the following 3 lines:

          window.setTimeo ut(&amp;#34;ale rt(
          \\&amp;#34;I\&# 39;m a/n \\&amp;#34;+
          window.frameEle ment.tagName)&a mp;#34;,0);

          In this case, the alert does not hold up processing until
          the onLoad of IFrame 1 has finished (by the alert being
          responded to). Rather, that onLoad finishes along with
          the others so that everybodyLoaded can run.

          In IE6, the alert from everybodyLoaded (run from the onLoad
          of IFrame 2) must be dismissed before the alert for IFrame 1
          (pending from the setTimeout) will run.

          However, in FF 1, both alerts will be shown, the IFrame 1
          alert on top of the everybodyLoaded alert.

          Csaba Gabor from Vienna

          Comment

          • kaeli

            #6
            Re: iFrames Page load

            In article <42777bc4$0$342 $4d4efb8e@read. news.be.uu.net> , jeb@fernbach.co m
            enlightened us with...[color=blue]
            >
            > I don't know if this works for Mozilla or Opera, but using IE, you could
            > check the readyState[/color]

            MSIE only[color=blue]
            > http://msdn.microsoft.com/workshop/a...adystate_1.asp[/color]
            Standards Information
            There is no public standard that applies to this property.

            --
            --
            ~kaeli~
            A lot of money is tainted - It taint yours and it taint mine.



            Comment

            • adnanx82@gmail.com

              #7
              Re: iFrames Page load

              Thanks for your replies. Keeping a count of frames loaded works if the
              frames are produced statically in the html. However, if there is
              javascript code that generates frames dynamically, we don't know for
              sure what the number of frames would be in the frames array when the
              onLoad event is called for a particular frame (There might still be
              more frames being added to the document).

              I think setting variables in each frames window and container window
              when that window's onLoad event fires might work. After setting the
              variable, it could go through all the frames in the top window and if
              all of them have the variable set to true, then we know that that
              onLoad was the last onLoad and the page (with all the component
              windows) has finished loading. However, again, I am not sure what the
              implication is on pages which dynamically generate frames or iframes
              using document.write( )...Will this work all the time? Is it possible
              that all the frames in the frames array and the container page have
              finished loading but there still other frames that are just about to be
              added?

              In case you're wondering, I'm writing a generic solution, so I don't
              know about the structure of the pages and would like to have a generic
              way of figuring out the completion of the load for a container page
              along with all of its component frames/iframes.

              Thanks very much for your help everyone.

              -Adnan.

              Comment

              Working...