468,760 Members | 1,764 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,760 developers. It's quick & easy.

modify frame 'onload' ?

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[i];
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.

Nov 1 '05 #1
6 2310
pi********@gmail.com wrote:
<snip>
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.
Nov 2 '05 #2
> 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.

Nov 2 '05 #3
pi********@gmail.com wrote:
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 ?


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.
Nov 2 '05 #4

pi********@gmail.com wrote:
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[i];
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[i];
iframe.onload=....;

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

Julian

Nov 2 '05 #5

Julian Turner wrote:
pi********@gmail.com 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

Nov 2 '05 #6
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.

Nov 2 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Robert Oschler | last post: by
2 posts views Thread by Halldór Ísak Gylfason | last post: by
2 posts views Thread by RWD | last post: by
5 posts views Thread by Tim Streater | last post: by
2 posts views Thread by torext | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.