How to detect iframe doc change and loading

A

Asterbing

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

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top