473,288 Members | 1,726 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,288 software developers and data experts.

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="JavaScript"><!--
var f = document.getElementById("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 WaitStats4Checking(){
if (f.document.readyState == "complete"){
Check();}
else{
setTimeout("WaitStats4Checking()",50);}}

function GetStats(){
var f = document.getElementById("stats");
f.setAttribute("src", "stats.htm"); // real url will be to
a CGI
WaitStats4Checking();}
//--></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.readyState == "complete") is always
true even if generated document is not fully loaded.
<br><br>
How to solve this ? Maybe going through onreadystatechange to launch
WaitStats4Checking() rather than at the end of GetStats(), but how ?</p>

<a href="#" onclick="GetStats();">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="yes"
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 7077


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="yes"
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(event.type);"
src="whatever.html" name="iframeName"></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***********************@newsread4.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="yes"
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(event.type);"
src="whatever.html" name="iframeName"></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.addEventListener){
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
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...
5
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...
4
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...
6
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...
6
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
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: 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...
3
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...
3
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. ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.