473,703 Members | 4,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect iframe's doc change/loading ?

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).

All is said in the three HTML file I've copied below. Just create the
three in same directory, then launch main.htm.

-- Begin of MAIN.HTM --
<html>
<head>
<title>Check Statistics</title>
<script type="text/javascript" language="JavaS cript"><!--
var f = document.getEle mentById("stats ");

function Check(){
alert("Check() called : means doc should be loaded in
iframe. The real Check() fct will do several things including : iframe's
heigh resize to fit the doc heigh, some stats summarization on screen
and creation of some buttons about copy/export");}

function WaitStats4Check ing(){
if (f.document.rea dyState == "complete") {
Check();}
else{
setTimeout("Wai tStats4Checking ()",50);}}

function GetStats(){
var f = document.getEle mentById("stats ");
f.setAttribute( "src", "stats.htm" ); // real url will be to
a CGI
WaitStats4Check ing();}
//--></script>
</head>
<body>
<p>Initially, the iframe contains help.htm which just says "Not any
statistic loaded. Click 'Get Statistics'" for which a heigh of 20px is
enough.
<br><br>
When user click on the 'Get Statistics' link, the GetStats() javascript
function run the getstats.exe CGI script which returns a generated
document in iframe.
<br><br>
When this generated document is well loaded in iframe (not before), the
Check() javascript function should be launched.
<br><br>
Current problem is that (f.document.rea dyState == "complete") is always
true even if generated document is not fully loaded.
<br><br>
How to solve this ? Maybe going through onreadystatecha nge to launch
WaitStats4Check ing() rather than at the end of GetStats(), but how ?</p>

<a href="#" onclick="GetSta ts();">Get Statistics</a>

<div style="position : absolute; visibility: visible; top: 300px; left:
15px; height: auto; width: 731px; padding: 5px; overflow: hidden;
background: white; color: #000000">
<iframe id="stats" width=720 height=60 src="help.htm" frameborder="ye s"
scrolling="no"> </iframe>
</div>
</body></html>
-- End of MAIN.HTM --
-- Begin of HELP.HTM --
<html><head></head><body>
Not any statistic loaded. Click 'Get Statistics'
</body></html>
-- End of HELP.HTM --
-- Begin of STATS.HTM --
<html><head></head>
<body>
Normally, this document is generated through a CGI, but I've created a
dummy HTML file for facility during the test.
<br><br>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc feugiat
diam eu risus. Proin hendrerit mauris commodo enim bibendum dictum.
Pellentesque eu libero eu lorem consequat varius. Sed ornare mauris eu
erat. Vivamus malesuada consequat turpis. Etiam nec massa. Donec risus
urna, semper a, pellentesque quis, malesuada non, mi. Sed quis nibh.
Donec vulputate tortor eu pede. Donec volutpat, leo eu commodo nonummy,
elit pede pretium diam, a scelerisque nunc magna vitae massa. Fusce sit
amet nibh vitae sapien faucibus feugiat. Sed nisl. Nullam commodo luctus
metus. Sed elit. Cum sociis natoque penatibus et magnis dis parturient
montes, nascetur ridiculus mus. Fusce nunc arcu, aliquam vel, dignissim
vel, auctor sit amet, justo. Suspendisse cursus felis eu ipsum. Praesent
ac massa. Integer laoreet rhoncus elit. Sed mi lectus, dictum
adipiscing, sodales sit amet, congue a, diam. Donec feugiat ligula id
ante. Donec eget lacus. Etiam dui. Nullam nisi. Maecenas elit. Aenean
lectus sem, pellentesque nec, placerat id, tempus sollicitudin, risus.
Praesent fermentum tempor velit. Nulla dolor. Ut condimentum. Nulla
lobortis lacinia nisl. Donec leo. In pellentesque luctus sapien. Nulla
ultricies lacinia odio. Etiam ornare lacus. Aenean ut lacus. Proin
tortor augue, eleifend sed, imperdiet id, iaculis eu, augue. Nulla
tempus orci ac leo. Maecenas purus. Etiam varius porta mauris. Donec
porta, tortor a suscipit accumsan, libero dui hendrerit tortor, quis
faucibus nisi turpis non mauris. Maecenas elit tortor, viverra nec,
ornare sit amet, porta eget, quam. Integer ultrices, diam vitae sagittis
scelerisque, ligula velit sodales justo, vel ultricies nulla ipsum
suscipit arcu. Aenean sed nibh quis ipsum tempor vehicula. Integer
eleifend ante vel leo. Fusce diam metus, porttitor sed, viverra id,
convallis in, arcu. Nullam luctus, massa at consectetuer scelerisque,
elit nisl eleifend erat, luctus laoreet odio pede sed ipsum. Sed a enim
nec libero cursus euismod. Aliquam non nisi eleifend turpis fringilla
porttitor. Pellentesque ut felis sit amet lectus accumsan fringilla.
Aliquam vitae arcu vitae mauris ullamcorper volutpat. Nulla elementum
tincidunt quam. Ut auctor mauris eget magna. Aliquam pulvinar sapien id
libero. Phasellus at est in erat accumsan egestas. Duis vel neque.
Maecenas facilisis, dui id dignissim tincidunt, sem tellus gravida
dolor, eu sollicitudin justo tellus in erat. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Phasellus ante erat, viverra eget, condimentum in, ultrices et, tortor.
Pellentesque feugiat tincidunt justo. Proin iaculis mi sit amet felis.
Donec sit amet leo. In porta. Donec condimentum. Ut nunc mauris, euismod
at, congue eget, scelerisque sed, quam. Proin bibendum, arcu non auctor
gravida, purus nisi consequat turpis, vel aliquam orci velit sit amet
dolor. Donec cursus elit et sem. Aenean auctor lectus non tortor.
Praesent ac leo quis risus porttitor blandit. Vestibulum ante ipsum
primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc
lobortis sodales nulla. Praesent ornare condimentum lectus. Donec a
pede. Aliquam libero. Donec orci ipsum, convallis in, semper at, feugiat
id, ipsum. Phasellus nisi erat, cursus eget, commodo eget, feugiat nec,
nibh. Mauris pretium cursus arcu. Nullam molestie consequat sem. Nullam
velit lacus, tristique a, suscipit ac, pretium eget, sem. Vivamus vitae
purus. Donec vulputate, dolor id luctus dapibus, enim purus viverra
magna, vitae dignissim turpis magna ac nunc. Proin venenatis. Aenean
quis ante sed ligula imperdiet posuere. Donec ante nibh, fringilla nec,
suscipit in, blandit ut, massa. Vivamus sed erat. Pellentesque neque
leo, lobortis porttitor, interdum id, bibendum id, nulla. Aliquam sed
arcu. Morbi feugiat. Nunc bibendum. Etiam risus. Nam aliquet. Curabitur
placerat, ligula a consequat pellentesque, nunc arcu gravida quam, at
aliquet orci augue ac nunc. Morbi in dui vehicula ipsum ullamcorper
pellentesque. Curabitur nec nisl. Curabitur laoreet volutpat neque. Cras
elit sem, blandit ut, tempus in, dignissim non, nulla. Morbi ornare
placerat est. Aliquam nec tortor. Praesent turpis quam, venenatis
gravida, tempor eu, imperdiet interdum, sapien. Morbi pharetra, orci
porttitor tempor euismod, lacus est congue est, vel ultrices velit
tellus ac lacus. Donec semper semper elit. Praesent at nibh ut velit
euismod porttitor. Donec nec odio. Suspendisse dictum, dui vel iaculis
eleifend, velit nisi mattis nulla, sit amet egestas est lectus non
metus. Suspendisse velit est, sagittis at, sollicitudin sit amet,
faucibus in, turpis. Sed non lorem. Duis lectus orci, posuere molestie,
mollis id, tempus congue, mi. Nullam ante lorem, molestie eu, euismod
in, tempor et, lorem. Sed varius. Morbi laoreet, turpis vitae tincidunt
ullamcorper, arcu sapien gravida lacus, ut vulputate elit pede in dolor.
Suspendisse suscipit nibh sed ligula. Aenean neque orci, semper eget,
ornare vestibulum, ullamcorper quis, odio. Donec tempor sagittis sapien.
Morbi ut sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Sed laoreet facilisis sapien. Mauris lacinia. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec
condimentum tellus eget turpis. Vivamus egestas. Class aptent taciti
sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos.
Quisque vel lacus vel nisl faucibus dictum. Nunc porttitor. Donec
mollis. Praesent vel turpis. Etiam nunc. Pellentesque hendrerit. Nullam
vitae risus. Nam aliquet porttitor ligula. In justo massa, iaculis eget,
gravida ac, lacinia et, magna. Nullam consectetuer. Aliquam adipiscing
ipsum ac lorem. Curabitur et sem eu erat mattis cursus. Integer auctor
posuere risus. Vestibulum ante ipsum primis in faucibus orci luctus et
ultrices posuere cubilia Curae; Proin pulvinar massa. Generated 10
paragraphs, 862 words, 5852 bytes of Lorem Ipsum
</body>
</html>
-- End of STATS.HTM --
Mar 13 '06 #1
3 7129


Asterbing wrote:

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). <iframe id="stats" width=720 height=60 src="help.htm" frameborder="ye s"
scrolling="no"> </iframe>


You can put an onload handler on the iframe element with IE 5 and later,
with Mozilla/Firefox, and with Opera 8.5 e.g.
<iframe onload="alert(e vent.type);"
src="whatever.h tml" name="iframeNam e"></iframe>
That is not valid HTML 4 or XHTML 1.0 however. If that is an issue for
you then consider setting up the event listener with script instead of
using markup with the onload attribute.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 13 '06 #2
In article <44************ ***********@new sread4.arcor-online.net>,
ma*******@yahoo .de says...


Asterbing wrote:

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).

<iframe id="stats" width=720 height=60 src="help.htm" frameborder="ye s"
scrolling="no"> </iframe>


You can put an onload handler on the iframe element with IE 5 and later,
with Mozilla/Firefox, and with Opera 8.5 e.g.
<iframe onload="alert(e vent.type);"
src="whatever.h tml" name="iframeNam e"></iframe>
That is not valid HTML 4 or XHTML 1.0 however. If that is an issue for
you then consider setting up the event listener with script instead of
using markup with the onload attribute.


Thanks but does this iframe onload will be triggered everytime a new
document is generated inside it (from getstats.exe) ?

If yes, effectively, I would prefer to go through event listener
addition since I would like the most of browsers compatibility. Does
what you talk about was something like this (found through google) ? :

if (window.addEven tListener){
f.onload = Check();}
else if (f.attachEvent) {
f.attachEvent(" onload", Check());}
else{
return;}
Mar 13 '06 #3


Asterbing wrote:

but does this iframe onload will be triggered everytime a new
document is generated inside it (from getstats.exe) ?


That onload handler will be fired any time a document has been loaded in
the iframe.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8553
by: Robert Oschler | last post by:
I have a comparison web page that has several iframes that contain documents from external domain web sites. Some of the web sites are "trusted". If they want to change the top level document location (document.location.href) via Javascript or using "_TOP" as the target for a SUBMIT operation, etc., then I want to allow it. The other web sites I want to block if they try to do that. I would do the blocking in the top level document...
5
4214
by: Jim Marquardson | last post by:
Hi, I've struggled with this for a while now, so I'm asking for help. I am trying to click on a link in one page, have that link open up in a new window, and set that newly opened window's ifram to a specific url. Here is the code I'm using: <html> <head>
4
8993
by: Mark | last post by:
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...
6
12580
by: ok | last post by:
<img src="http://www.6park.com/enter2/av.gif" onload="document.write('an iframe obj');"> First of all, it destroy the HTML page. Secondly even if it does not destroy it, the iframe object will be within an img tag. How do I write a new iframe obj outside img tag?
6
3901
by: fniyogi | last post by:
Does anyone know how to suppress the "busy"/hourglass cursor that appears when a frame/iframe is loading, as in the g() functon below: <SCRIPT> function g() { if ( Math.floor(Math.random()*2) == 1 ) frames.location.href = "http://www.yahoo.com"; else frames.location.href = "http://games.yahoo.com"; }
1
2619
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
2431
by: Namshub | last post by:
I'm trying to create a dynamic link to different sources when a page loads (I want a set of buttons at the top before the IFrame) but the content of the IFrame will be dynamic but know when the page is loaded. How can I either generate the HTML on the fly as the form is loading or set the Src value of the IFrame tag as the page is loading? Thanks Ric
3
4486
by: PCgeek | last post by:
sorry moved this over to javascript forum, didn't mean to post 2x! Hi guys, I'm trying to put the finishing touches on my website and could really use some help on this particular issue. My page includes background music with a javascript music player on the main page below an iframe that is used for all content and navigation of the site and so that the music doesn't reload each time a page is switched. There is another javascript to resize...
3
4995
by: synergy_711 | last post by:
I feel like this should be fairly easy but I have been struggling with this for sometime. I have not been able to find someone who's had the same problem as mine yet. http://g.bach.home.insightbb.com/movies.html I have a page set up on my website to view videos from various sites by creating html pages and creating links to view them inside an iframe. I'm getting tired of creating pages for every video that I find and it seems to make...
0
8763
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8676
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9127
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9020
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7878
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6602
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2073
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.