473,581 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8984
"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.ht ml>.
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_nam e"].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_nam e"].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*********@we b.de> wrote in message news:<41******* *******@Pointed Ears.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.ht ml>.
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_nam e"].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
2559
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 loaded and then get its title to put in the main document. function GetTitle() { var
4
27992
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 javascript. Within this javascript that runs in test.html, I want to obtain the id of the iframe that loaded test.html in the first place. Is this...
3
3959
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 IsPostBack=False by now!. The ASPX is opened via client side script (into an iFrame) inside a .HTM file (as ASPX postback causes problems in a modal...
1
2613
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 you.
3
7116
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 loaded inside an iframe, knowing this document is CGI generated and that I can't modify the CGI itself (ie. add an onload event in the document body). ...
0
2127
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. When clicking "Download file..." on the information bar, a postback occurs. I would like to detect this postback. The file that is going to be...
2
4430
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 Acrobat Reader Plugin. In that case, the IExplorer shows an popup window with this message:
20
11855
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 (i=0;i<obj.length;i++) { obj.attachEvent('ondrag', noDrag); }
0
7862
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8169
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3803
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.