Working with Frames
Some browsers (including the latest Netscape and Microsoft browsers) support frames, which enable you to divide the browser window into multiple panes. Each frame can contain a separate URL or the output of a script.
Remember the window and self keywords, which refer to the current window? When you are using frames, these keywords refer to the current frame instead. Another keyword, parent, enables you to refer to the main window.
Each frame object in a window is a child of the parent window object. Suppose you define a set of frames using the HTML below:
<frameset ROWS="*,*" COLS="*,*"> <frame NAME="topleft" SRC="topleft.htm"> <frame NAME="topright" SRC="topright.htm"> <frame NAME="bottomleft" SRC="botleft.htm"> <frame NAME="bottomright" SRC="botright.htm"> </frameset>
If you use nested framesets, things are a bit more complicated. window still represents the current frame, parent represents the frameset containing the current frame, and top represents the main frameset that contains all the others.
The frames Array
Rather than referring to frames in a document by name, you can use the frames array. This array stores information about each of the frames in the document. The frames are indexed starting with zero and beginning with the first <frame> tag in the frameset document.
For example, you could refer to the frames defined in the previous example using array references:
parent.frames is equivalent to the topleft frame.
parent.frames is equivalent to the topright frame.
parent.frames is equivalent to the bottomleft frame.
parent.frames is equivalent to the bottomright frame.
You can refer to a frame using either method interchangeably, and depending on your application, you should use the most convenient method. For example, a document with 10 frames would probably be easier to use by number, but a simple two-frame document is easier to use if the frames have meaningful names.