Main Page

equal

<html>
<head>
<title>Frameset Example</title>
</head>
<frameset rows=”100,* “>
<frame src=”frame.htm” name=”topFrame” />
<frameset cols=”50%,50%”>
<frame src=”anotherframe.htm” name=”leftFrame” />
<frame src=”anotherframeset.htm” name=”rightFrame” />
</frameset>
</frameset>
</html>
Now what if there is also a file named
anotherframeset.htm
containing this code?
<html>
<head>
<title>Frameset Example</title>
</head>
<frameset cols=”100,* “>
<frame src=”red.htm” name=”redFrame” />
<frame src=”blue.htm” name=”blueFrame” />
</frameset>
</html>
When the first file,
frameset1.htm
, is loaded into the browser, it loads
anotherframeset.htm
into
rightFrame
. If code is written in
redFrame
(or
blueFrame
), the
parent
object points to
rightFrame
in
frameset1.htm
. If, however, code is written in
topFrame
, the
parent
object actually points to
top
because the browser window itself is considered the parent of any top-level frameset.
Figure 5-5 proves this fact by accessing the
window
object’s
name
property, which stores the name of the
frame (but will always be blank for
top
).
One more global window pointer, called
self
, is always equal to
window
(yes, a bit redundant, but it’s
included as a better fit with
parent
. It clarifies that you are not talking about the frame’s parent but the
frame itself.)
If there are no frames in the page,
window
and
self
are equal to
top
and the
frames
collection has a
length of 0.
It is also possible to chain references to
window
objects together, such as
parent.parent.frames
[“topFrame”]
, although this is generally frowned upon because any change in the frame structure
results in code errors.
138
Chapter 5
08_579088 ch05.qxd 3/28/05 11:37 AM Page 138


JavaScript EditorFree JavaScript Editor     Ajax Editor


©