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

M

Mark

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
 
J

Java script Dude

Mark said:
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
 
T

Thomas 'PointedEars' Lahn

Java said:
"Mark" <[email protected]> wrote in message news:<[email protected]>...

Please do not write attribution novels, see
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
 
T

Thomas 'PointedEars' Lahn

Thomas said:
[...] 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
 
J

Java script Dude

Thomas 'PointedEars' Lahn said:
Please do not write attribution novels, see


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top