|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Creating and Using FramesChapter 7, Frames, showed you how to create and use frames in your Web site. You can access and manipulate the contents of these frames by using the frame object. Each of the frames created in a document can be accessed through the frames object array, which is attached to the document object. The most important thing to remember about a frame object is that it is a window object. This means that each frame created is a separate window object, and all the properties, methods, and events associated with window objects can be applied. See Frames, page 211. Communicating Between FramesAfter you have created a series of frames by using the <FRAMESET> and <FRAME> tags, how do you use JavaScript to access and manipulate each frame? As mentioned in the preceding section, each frame is a separate window object. Therefore, if you can reference each frame, you can use the same techniques that were used with windows for each frame. The Web Browser Object Model includes several properties that apply to frame and window objects that make referencing different frames much easier. These properties are the self, window, parent, and top properties. Their meanings are as follows:
Understanding the Frames Object HierarchyConsider a simple frameset created using the following HTML code: <FRAMESET ROWS="50%,50%"> <FRAMESET COLS="50%,50%"> <FRAME SRC="Form.htm" NAME="MyFrame1"> <FRAME SRC="Form.htm" NAME="MyFrame2"> </FRAMESET> <FRAME SRC="Frameset2.htm" NAME="MyFrame3"> </FRAMESET> This divides the window into three frames: two side-by-side on the top half of the window, and a third occupying the entire bottom half. The object model for this document will appear as shown in Figure 20.11.
Given the object hierarchy shown in Figure 20.11, you would reference the frame objects as follows:
Now, what if you introduce another generation to your framed document? The third frame might load an HTML document that itself contains a <FRAMESET> tag to further divide the window into more frames, as in the following: <FRAMESET COLS="33%,33%,*"> <FRAME SRC="Form.htm" NAME="MyFrame1"> <FRAME SRC="Form.htm" NAME="MyFrame2"> <FRAME SRC="Form.htm" NAME="MyFrame3"> </FRAMESET> This would result in the object hierarchy shown in Figure 20.12.
This would result in a window showing a total of five frames. The top half of the window would show two frames, part of the first generation of frame objects. The bottom half of the window would show three frames, part of the second generation of frame objects. The following examples show you ways to reference the document object of the different generations of frames and parent framesets:
Multiple Frame Access ExampleListings 20.12 through 20.14 show an example of the kind of multiple frame, multiple generation frame setup discussed in the preceding section. Notice that a few things from this example demonstrate the object-oriented nature of JavaScript, which gives you the flexibility to accomplish multiple things.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |