469,616 Members | 1,774 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

How can I detect when a file has completely loaded into an iframe?

I am loading source files into several iframes, with each load happening
after some user-generated event (like clicking a button). The loading works
but I need to determine when the source file is FULLY loaded so I can do
some calcs on its scroll height within the frame. If I check the scroll
height right away (after fetching the file), it's wrong (some small number)
but if I wait a couple of seconds I get the right value. I need to do
better than just guessing when the file has been loaded.

Ideas?

Thanks,
Mark
Jul 23 '05 #1
4 8650
"Mark" <Ma*******@gems.gov.bc.ca> wrote in message news:<41******@obsidian.gov.bc.ca>...
I am loading source files into several iframes, with each load happening
after some user-generated event (like clicking a button). The loading works
but I need to determine when the source file is FULLY loaded so I can do
some calcs on its scroll height within the frame. If I check the scroll
height right away (after fetching the file), it's wrong (some small number)
but if I wait a couple of seconds I get the right value. I need to do
better than just guessing when the file has been loaded.


The best way is to write an asyncronous thread in the parent window
using setTimeout script for interval control. In the window you are
watching, set a global boolean flag in javascript at the bottom of the
body. You could also set the global boolean (window.bLoaded=true) on
body.onload().

Have the parent window watch for this boolean. Just remember to set
the boolean to false when requesting another url that way the program
does not detect the window already opened.

I've used this technique succesfully for my DHTML App model where I
send a data light weight data request in an iFrame and watch for the
response from the server then parse the window when it comes back.

JsD
Jul 23 '05 #2
Java script Dude wrote:
"Mark" <Ma*******@gems.gov.bc.ca> wrote in message news:<41******@obsidian.gov.bc.ca>...


Please do not write attribution novels, see
<http://www.netmeister.org/news/learn2quote2.html>.
I am loading source files into several iframes, with each load happening
after some user-generated event (like clicking a button). The loading works
but I need to determine when the source file is FULLY loaded so I can do
some calcs on its scroll height within the frame. If I check the scroll
height right away (after fetching the file), it's wrong (some small number)
but if I wait a couple of seconds I get the right value. I need to do
better than just guessing when the file has been loaded.


The best way is to write an asyncronous thread in the parent window
using setTimeout script for interval control. In the window you are
watching, set a global boolean flag in javascript at the bottom of the
body. You could also set the global boolean (window.bLoaded=true) on
body.onload().


I don't think you got him right. How is he supposed to add a script
to a document that holds the source file (he never said it's a (X)HTML
document) he wants to *display* in the iframe?

So AIUI the issue is not how to determine that a script in the source
file has loaded but to determine that the displayed source file itself
has finished loading within the iframe. Alas the "iframe" element does
not provide for an "onload" attribute, but Window objects do have a
"onload" property. So it could work to refer to the "iframe" element
object as a Window object and set its "onload" property to a reference
to an event listening method.

document.frames["iframe_name"].onload = function() { alert(42); };
HTH

PointedEars
Jul 23 '05 #3
Thomas 'Ingrid' Lahn wrote:
[...] So it could work to refer to the "iframe" element
object as a Window object and set its "onload" property
to a reference to an event listening method.

document.frames["iframe_name"].onload = function() { alert(42); };


Arghl. window.frames... or just frames... of course.
PointedEars, not as awake as he thought
Jul 23 '05 #4
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote in message news:<41**************@PointedEars.de>...
Java script Dude wrote:
"Mark" <Ma*******@gems.gov.bc.ca> wrote in message news:<41******@obsidian.gov.bc.ca>...
Please do not write attribution novels, see
<http://www.netmeister.org/news/learn2quote2.html>.
I am loading source files into several iframes, with each load happening
after some user-generated event (like clicking a button). The loading works
but I need to determine when the source file is FULLY loaded so I can do
some calcs on its scroll height within the frame. If I check the scroll
height right away (after fetching the file), it's wrong (some small number)
but if I wait a couple of seconds I get the right value. I need to do
better than just guessing when the file has been loaded.


The best way is to write an asyncronous thread in the parent window
using setTimeout script for interval control. In the window you are
watching, set a global boolean flag in javascript at the bottom of the
body. You could also set the global boolean (window.bLoaded=true) on
body.onload().


I don't think you got him right. How is he supposed to add a script
to a document that holds the source file (he never said it's a (X)HTML
document) he wants to *display* in the iframe?

This is true, if it is not (X)HTML the above will not work.
So AIUI the issue is not how to determine that a script in the source
file has loaded but to determine that the displayed source file itself
has finished loading within the iframe. Alas the "iframe" element does
not provide for an "onload" attribute, but Window objects do have a
"onload" property. So it could work to refer to the "iframe" element
object as a Window object and set its "onload" property to a reference
to an event listening method.

document.frames["iframe_name"].onload = function() { alert(42); };


Onload functions don't always work for all browsers though but I have
tested onloads with IE and Moz and they work in both.

With my example, if the boolean is set at the end of the body, you can
pretty much assume that the document is fully loaded which 'should'
give you the same effect as iframe.onload. But iframe.onload is just
so much cleaner.

JsD
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by christine.nguyen | last post: by
3 posts views Thread by Stevie_mac | last post: by
3 posts views Thread by Asterbing | last post: by
2 posts views Thread by =?Utf-8?B?QWxoYW1icmEtRWlkb3MgS2lxdWVuZXQ=?= | last post: by
20 posts views Thread by Mark Anderson | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.