473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 8963
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eli | last post by:
Hi, I've created a dynamic IFRAME and inserted it in the document. Then I changed the src property to some URL (not the same domain as the main document). I want to check when the IFRAME is...
4
by: christine.nguyen | last post by:
Hello, Here's the deal. I have an html page that contains an iframe. This iframe has an id that is unknown to me. This iframe also has test.html as it's source. Within test.html runs some...
3
by: Stevie_mac | last post by:
It might be me but... I dont seem to get a Page_Load event when a opening an ASPX in an iFrame. I do geta Page_Load event when an item on the ASPX (inside the iFrame) is clicked but then...
1
by: Alex | last post by:
I need to detect if page loaded or not with a script (in a child frame). The IE has a special readyState function, is there anything similar for Mozila browsers? Is there a work around? Thank...
3
by: Asterbing | last post by:
Since the "on fly addition..." thread has taken another direction, I'm opening a new one to be more explicit and recenter the subject. Well, the subject is to detect when a document is well...
0
by: ar | last post by:
Hello, In IE I disable "Automatic prompting for file downloads" which causes the IE information bar to show up when I try to push a file download from an iframe. I want to keep this behaviour. ...
2
by: =?Utf-8?B?QWxoYW1icmEtRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello misters, I have a ASPX that contains an IFrame to display a PDF file. Like this: <iframe src="/Files/MyPDF.pdf"></iframe> I have an problem about it, if an user hasn't installed...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.