在 frame 之间 调用函数

原文
[url]http://sharkysoft.com/tutorials/jsa/content/038.html[/url]

mixing functions and frames

[i] I have three files, a "parent frame" file and the two files which are loaded into the frames set up by the parent. Also in the parent frame I have a javascript function defined.

In one of the frames, I need to call that function in the parent frame. I have it set up like so:

<BODY onLoad="parent.buildindx();">

In MS Internet Explorer it works great. It does just what I want it to. However, in Netscape 3.01, it gives me an error saying "window.buildindx not a function".

It seems as though, in Explorer, it allows it to be called using the parent (window) object, but in Netscape it doesn't recognize it.

I may be doing something wrong, but I would appreciate any advice you could give me.

-- John[/i]

When a JavaScript function is defined in a document, the function becomes a method of the window or frame object in which it is defined. In JavaScript, windows and frames are treated similarly, and for the purposes of this article I will use the term "frame" to indicate either "frame" or "window."

In order for one frame to call a function defined in another frame, the caller must have a reference to the frame object containing the function. In most cases, this is just

[b] parent . frame_name [/b]

In a two-framed document containing frames named "left" and "right," for example, the left frame can call the right frame's functions through the expression

[b]parent . right . function_name (parameters) [/b]

Similarly, to call a function defined in the parent, or frameset document, all you need is a reference to the parent. Thus, the expression

[b] parent . function_name (parameters) [/b]

is sufficient to call the parent frame's functions.

It appears that this is exactly what you were trying to do -- that is, to call a parent frame's function from within a child frame. Based on what you have told me, it also appears that your code is correct. So why, do you suppose, does it work in Internet Explorer but not in Netscape Navigator?

I did some research for you and came up with a startling conclusion. The current release of Netscape completely ignores JavaScript that is placed after the opening <frameset> tag of a frameset document. This means that if you want to call a function defined in a frameset document, the function definition should occur before the first <frameset> tag.

Charlton Rose
April 25, 1997
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值