473,887 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On fly addition of an onload event to an iframe document

Hi,

Talking about a js script which changes an iframe src through a "ref_to
iframe.setAttri bute("src", document_path); ", I would like to launch a
check() fct when this new document is loaded.

Of course, knowing, I don't want (and can't n some cases where document
is generated by a cgi script) to edit every possible document which is
potentially loadable in the iframe.

In fact, I've through about the idea to on fly add an "onload='ch eck
()';" to every document, but don't know how to do that :-(

Maybe using attachEvent or something arounnd this : I don't know. Of
course, I wish a solution working in the majors browsers.

How to do ?
Thanks in advance
Mar 12 '06 #1
7 9771
In article <MP************ ***********@new s.tiscali.fr>, no@thanks.com
says...
Talking about a js script which changes an iframe src through a "ref_to
iframe.setAttri bute("src", document_path); ", I would like to launch a
check() fct when this new document is loaded.


Close to be solved with a call to this fct after src change :

function wait4newdoc()
{
if (ref_to_iframe. document.readyS tate == "complete") {
check();}
else{
setTimeout("wai t4newdoc()",50) ;}
}

But it doesn't work everytime. Maybe a problem about readyState ?
Mar 12 '06 #2

Asterbing wrote:
Close to be solved with a call to this fct after src change :

function wait4newdoc()
{
if (ref_to_iframe. document.readyS tate == "complete") {
check();}
else{
setTimeout("wai t4newdoc()",50) ;}
}

But it doesn't work everytime. Maybe a problem about readyState ?


MSDN states: "The readyState property enables the status of an object
to be tested. The correct place to test the readyState property is in
the event handler for onreadystatecha nge..."
Try this:

document.onread ystatechange=fo o;

function foo(){
if (document.ready State=="complet e") {
...
}
}

Mar 13 '06 #3
In article <11************ *********@j33g2 000cwa.googlegr oups.com>,
ma***@ukr.net says...
document.onread ystatechange=fo o;


When you talk about document, do you talk about window.document or
ref_to_iframe.d ocument.

If this is the second one, it means I have to modify every document
which is loadable inside the iframe ? Do I have to go through something
like attachEvent or else ?

How to do this on fly, knowing every document is dynamically generated
from a cgi script I can't modify ?
Mar 13 '06 #4
In article <11************ *********@j33g2 000cwa.googlegr oups.com>,
ma***@ukr.net says...
MSDN states: "The readyState property enables the status of an object
to be tested. The correct place to test the readyState property is in
the event handler for onreadystatecha nge..."
Try this:


Well, to be more accurate, I've created a page which characterize the
problem. Just copy/paste. Here it is :

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

function WaitStats4Check ing(){
if (f.document.rea dyState == "complete"){Che ck();}
else{setTimeout ("WaitStats4Che cking()",50);}}

function GetStats(){
var f = document.getEle mentById("stats ");
f.setAttribute( "src","/cgi-bin/getstats.exe");
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=20 src="help.htm" frameborder="ye s"
scrolling="no"> </iframe>
</div>
</body></html>
Mar 13 '06 #5
Asterbing wrote:
var f = document.getEle mentById("stats "); .... function GetStats(){
var f = document.getEle mentById("stats ");

....

1.You used the same name for both local and global variables.
2.No need to use timeout to check readyState, WaitStats4Check ing is
called when state of document loaded in the iframe changed.

Next code has to work:

<script type="text/javascript" language="JavaS cript"><!--
function WaitStats4Check ing()
{
var f = document.getEle mentById("stats ");
if (f.readyState == "complete")
{
Check();
}
}

function GetStats()
{
var f = document.getEle mentById("stats ");
f.setAttribute( "src","http ://google.com");
f.onreadystatec hange = WaitStats4Check ing;
}

function Check()
{
alert("Check");
}

//--></script>

Sorry for my English.

Mar 13 '06 #6

Asterbing wrote:
var f = document.getEle mentById("stats "); .... function GetStats(){
var f = document.getEle mentById("stats ");

....

You use the same name for both local and global variables.

And no need to use timeout to check readyState, WaitStats4Check ing is
called when state of document loaded in the iframe changed.
Next code has to work:

<script type="text/javascript" language="JavaS cript"><!--
function WaitStats4Check ing()
{
var f = document.getEle mentById("stats ");
if (f.readyState == "complete")
{
Check();
}
}

function GetStats()
{
var f = document.getEle mentById("stats ");
f.setAttribute( "src","http ://google.com");
f.onreadystatec hange = WaitStats4Check ing;
}

function Check()
{
alert("Check");
}

//--></script>

Sorry for my English.

Mar 13 '06 #7
In article <11************ **********@i39g 2000cwa.googleg roups.com>,
ma***@ukr.net says...
Next code has to work:


Hum, I've asked through another approach in the "How to detect iframe's
doc change..." thread and been branched to the onload="Check() ;" way...
It sounds to work, unless the fact it doesn't work in all browsers. If I
don't succeed his way, I'll be back to your code. Thanks again, marss.
Mar 13 '06 #8

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

Similar topics

1
3065
by: Koms Bomb | last post by:
I create two iframes dynamically to get data from the server. I want to deal with the data after it's downloaded, so I set the two iframes' onload event handlers to current document(not the iframe self), the handlers' JS code is generated dynamically too. But I found only the second event is triggered and I can't get the first iframe's onload event. Why? The data in the first iframe is really arrived, but it doesn't trigger the onload...
2
9553
by: Rich | last post by:
Is there any way I can check to see if a document is loaded into the iframe before I call onLoad (sort of an afterLoad). I'm loading up a page into an iframe. But because we use four servers which use load balancing, the content isn't specified straight away. Therefore as I'm using onload to resize the iframes scroll bars to the size of the iframe content, I need to wait for this to be loaded first. Is there an alternative to onLoad that...
6
2768
by: pierre.bru | last post by:
hi, I encounter troubles with frames :( witht he folowing script in the _top page function walk(_frames) { for(var i=0; i<_frames.length; i++) { var frame = _frames; alert(frame.name);
5
2801
by: Andy Fish | last post by:
Hi, I have an asp.net web application which uses a pop-up form that works a bit like a dialog box. when the user clicks "OK" it does a postback (basically a form post if you don't know .net) to save the contents of the form, and then I put an onload event to do a window.close. this works fine for hundreds of people on different browsers. However, for one user the window does not close.
8
64017
by: niebo077 | last post by:
Look at the following code: <html> <head> </head> <body> <iframe id="olaf" name="olaf" onload="alert('no');"></iframe><br> <input type="submit" onclick="document.getElementById('olaf').src = 'phpinfo.php'" value="Test">
0
5897
by: dimepiece18 | last post by:
On our Intranet homepage, I have a layer with an iframe contained in it. The iframe is linked to an html document that is stored in our Content Library system. You have to be authorized to view the documents in Content Library. The problem I'm having is that when you launch the Intranet site, the SSO login screen appears, but it looks like the iframe is trying to launch the html file before the homepage loads. So after you log in, the iframe...
7
9651
by: Tom Cole | last post by:
IFrames have been used by years for people to accomplish many of the tasks the XMLHttpRequest does for them now...I unfortunately am late in the game and XMLHttpRequest was already out there by the time I got serious about using Javascript for more than just rollover images... I now would like to learn about the concept for the purposes of creating Ajax-like requests across domains. I felt like I had the basic concept down, but am...
13
3606
tpgames
by: tpgames | last post by:
What is the onload event handler needed to get # assigned to parent variable? What I tried didn't work! Code is from JS bible, page 127-8 with some minor alterations by me. Parent Page (in part) <!-- start function goNext() { var currOffset = parseInt(parent.currTitle); if (currOffset < 40) { currOffset +=1; parent.cryptogram.location.href = "http://www.tpgames.net/gaming/2/word/cipher/f/c/c" + currOffset + ".html";...
0
9957
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
10770
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
10875
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
10432
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
9593
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
7988
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
5809
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4632
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
2
4238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.