The Frame object is an indexed array that represents the frames used if the document is a framed document. It is a child of the Window object and each frame in a framed document is a property of the Frames array object, as described here.

PropertiesMethodsEvents
name, parent, length, self, window, frames setTimeout, clearTimeout Uses only Onload, OnUnLoad, OnFocus, or OnBlur, as used in the <FRAMESET> or <BODY> elements.

Frame objects are the separate windows created by a <FRAMESET> document. Each separate frame is it's own object (a property of the Window object) and also a property of the frames array object of the Frame object. This may sound confusing, but it's relatively simple. Each frame created by a frame document, is a property of the window object and is also a member of the frames array object, which is a property of both the window and frame objects. For example, consider the following documents :

<FRAMESET COLS="250,*">
<FRAME SRC="toc.htm" NAME="contents">
<FRAME SRC="main.htm" NAME="main">
</FRAMESET>

<FRAMESET ROWS="100,*">
<FRAME SRC="title.htm" NAME="title_bar">
<FRAME SRC="intro.htm" NAME="main2">
</FRAMESET>

where the second document is actually main.htm as loaded into the right hand window specified in the first document. Together, they specify a three window layout for the doucment. In such a document, each separate window can be referenced as :

window_name.Frame_Name.property

which is referencing the frame as an object, by using it's NAME attribute (i.e. for the window that contains "intro.htm", this would be main2), or can be referenced as :

window_name.frames(index).property

which is referencing the window as part of the frames array object, by using it's index to locate the frame window in the current browser window.

NOTE : the frame names, 'self', 'parent' and 'top' can also be used to reference particular frames in a framed document.

A note about frame indexing and parent/top relationships
Frame indexes always start at 0, not 1. So, to reference the frame named main2 in the example setup above, you could use :

window_name.frames(2).property

Also, it can be referenced as :

window_name.main2.property

Also, note that within nested frame documents (as the example above is, i.e. a <FRAMESET> that contains other <FRAMESET>s, the second set of frames (defined in the second document) can be referenced as properties of the first frame set. That is :

window_name.frames(2).property
window_name.main2.property
window_name.frames(1).frames(1).property

all target the same frame, the last one (i.e. main2 frame containing "intro.htm"). With the last reference, the frame is located as the second frame in the array of frames contained in the first frame object.

Also, in nested frames, the relationship between the locations of top and parent needs to be understood. For either of the secondary frames (i.e. those named title_bar and main2), using reference values of top and parent (or using <A HREF="..." TARGET="_top|_parent"> in any <A> hyperlinks) would have distinct differences. As these two frames can be considered children of the second window defined in the first document, then making any references using parent (or using <A ... TARGET="_parent">) would load the referenced document into the right hand window of the first frame set (the parent window of the two windows title_bar and main2). Using top (or <A ... TARGET="_top"> would load the referenced document into the whole window, first clearing any documents currently loaded.
For the document loaded into the left hand window (i.e. the window defined first in the first document, using top and parent (or <A ... TARGET="_top|_parent"> would do exactly the same as that particular window has no parent window.

Frame Properties
name
This property is the NAME attribute specified in the <FRAME> element that defines the particular window. For example, using :

vLocation=window.frames(1).name

would store the name of the second frame window in a frameset document in the variable vLocation.

parent
The parent property can be used to access the properties of the window that contains the current frameset. For example, the following sets the variable vNumFrames to the number of frames in the parent document (i.e. the toal number of frames in the parent document, of which the current document is one of).

vNumFrames=window.parent.length

length
This property stores the number of frames in any given framed window. It is strictly a property of the frames array rather than any particualr frame object. The example above serves to show a possible use of the length property of the frames array.

self
The self property is used to access properties of the current frame window.

window
The window property is used to access properties of the current frame. For more information, see the Window Object.

frames
As seen a few times above, the frames array property is an indexed array of any number of frames, contained in the current, top, parent, or any properly referenced window.

Frame Methods
setTimeout
As also used in the Window object, the setTimeout method can be used to execute a script function, or access any existing object property or method, after a specified time interval. For example, the following code section would execute the script function TooMuchTime() after 5 seconds :

MyTimeOut=setTimeout ("TooMuchTime()", 5000)

The time interval is always specified in milliseconds.

clearTimeout
As also used in the Window object, the clearTimeout method is used to clear a specified setTimeout method, by referencing it by the ID of the setTimeout method. For example, to clear the setTimeout given in the previous example, use the following code :

clearTimeout MyTimeOut

Frame Events
The frame obejct (and frames array) do not actually directly use any unique event hanlders. They can be controlled by use of the OnLoad, OnUnLoad, OnBlur and OnFocus event hanlders of the <FRAMESET> amd <BODY> elements. For more details, see the Scripting the <FRAMESET> element and Scripting <BODY> element topics respectively.


The Window Object Scripting Object Model Overview The History Object