O'Reilly logo

Beginning JavaScript®, Fourth Edition by Jeremy McPeak, Paul Wilton

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 8. Windows and Frames

Until now, the pages you have been looking at have just been single pages. However, many web applications use frames to split up the browser's window, much as panes of glass split up a real window. It's quite possible that you'll want to build web sites that make use of such frames. The good news is that JavaScript enables the manipulation of frames and allows functions and variables you create in one frame to be used from another frame. One advantage of this is that you can keep common variables and functions in one place but use them from many places. This chapter starts by looking at how you can script across such frames.

A number of other good reasons exist for wanting to access variables and functions in another frame. Two important reasons are to make your code modular and to gain the ability to maintain information between pages.

What does modular mean? In other programming languages, like C, C++, or Visual Basic, you can create a module — an area to hold general functions and variables — and reuse it from different places in your program. When using frames, you can put all of your general functions and variables into one area, such as the top frame, which you can think of as your code module. Then you can call the functions repeatedly from different pages and different frames.

If you put the general functions and variables in a page that defines the frames that it contains (that is, a frameset-defining page), then if you need to make changes to ...

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