O'Reilly logo

JavaScript® 24-Hour Trainer by Jeremy McPeak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Scripting Frames

The previous two lessons focused on the window object — a programmatic representation of the browser window. The browser window typically contains one web page, and thus only one window object. The <frameset/> element, however, allows web developers to divide a browser window into two or more smaller window panes.

Each of these panes is itself a browser window, and as such has a full-fledged window object. In fact, some browsers allow you to move and resize an individual frame with the moving and resizing methods you learned in Lesson 11 (it is highly recommended that you do not use these methods on a frame).

Arguably the most important aspect of dealing with frames as a JavaScript developer is accessing code and objects across frames. Over the course of this lesson you'll see many similarities between cross-frame scripting and cross-window scripting.

FRAMES AND THE WINDOW OBJECT

The easiest way to delve into frame scripting is with a demonstration. The first item you'll look at is the frameset page. Its HTML is as follows:

<html>
<head>
    <title>Frameset Page</title>
</head>
<frameset rows="50%,*">
    <frame name="frmTop" src="frame_top.htm" />
    <frame name="frmBottom" src="frame_bottom.htm" />
</frameset>
</html>

This is a simple frameset page: It divides the page into upper and lower regions. The frame on top, named frmTop, loads the frame_top.htm page into it, and the bottom frame, frmBottom, loads frame_bottom.htm. Make note of each frame's name, as they are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required