modify frame 'onload' ?

P

pierre.bru

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);
walk(frame.frames);
}
}
walk(window.frames);

I can walk thru all the frames and display their name. what I want to
do is to modify their 'onload' script to be notified when the frame
content has changed (no, I can not set onload='...' in the html) but
even if I set onload='top.myproc(...)', this top.myproc is never called
:(

is it possible ?

TIA,
Pierre.
 
R

Richard Cornford

I can walk thru all the frames and display their name. what
I want to do is to modify their 'onload' script to be
notified when the frame content has changed (no, I can not
set onload='...' in the html) but even if I set
onload='top.myproc(...)', this top.myproc is never called :(

Yes, that isn't going to work because the act of loading a page into a
frame re-sets the - onload - property of that frame's window/global
object. So any handlers you may externally assign to the property will
be removed prior to their ever getting a chance to execute.
is it possible ?

Broadly no. However, on recent IE versions and recent Mozilla versions,
and using the - attachEvent - and - addEventListener - methods (as
applicable) rather than assigning directly to the onload property, it is
possible to attach an event handler to an IFRAME element and have that
listener execute each time new contents load into the IFRAME. The IFRAME
element itself is not replaced when its contents change. I have never
tried doing the same with the FRAME elements within a FRAMESET but it is
probably worth a try. The results are certainly _not_ cross browser, and
there is no reason to expect this to work at all (that is; no public
specification implies that it should).

Richard.
 
P

pierre.bru

Yes, that isn't going to work because the act of loading a page into a
frame re-sets the - onload - property of that frame's window/global
object. So any handlers you may externally assign to the property will
be removed prior to their ever getting a chance to execute.

what do you mean by "the act of loading a page into a frame re-sets the
- onload - property of that frame's window/global object" ? that it
will be reseted to what is defined to in the html ?

Pierre.
 
R

Richard Cornford

what do you mean by "the act of loading a page into a frame re-sets
the - onload - property of that frame's window/global object" ? that
it will be reseted to what is defined to in the html ?

Yes, and if the HTML (or a script in (or imported by) the HTML) does not
set an onload handler than any existing handlers will just be
cleared/freed.

Richard.
 
J

Julian Turner

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);
walk(frame.frames);
}
}
walk(window.frames);

I can walk thru all the frames and display their name. what I want to
do is to modify their 'onload' script to be notified when the frame
content has changed (no, I can not set onload='...' in the html) but
even if I set onload='top.myproc(...)', this top.myproc is never called
:(

is it possible ?

TIA,
Pierre.


Hi. This is probably wide of the mark, and is again not cross-browser,
but do not IE and Mozilla support an onload event on the FRAME and
IFRAME element itself (as well as the window object)?

E.g. something like this (totally untested, probably wrong):-

function walk(_iframes)
{
for(var i=0; i<_iframes.length; i++)
{
var iframe = _iframes;
iframe.onload=....;

walk(iframe.contentWindow.document.getElementsByTagName("IFRAME"))
}
}
walk(document.getElementsByTagName("IFRAME"));

Julian
 
J

Julian Turner

Julian said:
(e-mail address removed) wrote:

Hi. This is probably wide of the mark, and is again not cross-browser,
but do not IE and Mozilla support an onload event on the FRAME and
IFRAME element itself (as well as the window object)?

Richard Cornford wrote
rather than assigning directly to the onload property, it is
possible to attach an event handler to an IFRAME element and have that
listener execute each time new contents load into the IFRAME. The IFRAME
element itself is not replaced when its contents change.

Sorry, just noticed that you mentioned this. Certainly the FRAME
element supports the onload event in IE.

Julian
 
P

pierre.bru

maybe IFRAMe would work.. or not. I can not test it as I can not modify
the HTML. the only entry point I have is a script in the _top page.

I tried to assign onunload instead of onload and I correctly get the
corresponding events. so now, i know that the frames can suspected to
be reloaded with a different content (suspected as the user may be
going to somewhere else, not modifying hte frmaes content).

maybe I can use that with some timer to check the potentially new frmae
content and reassign them onunload... duno :-/

in anyway, this will be harder that an onload

Pierre.
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top