Java Reference
In-Depth Information
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 vari-
ables 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 vari-
ables 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 defi nes the frames that it contains
(that is, a frameset-defi ning page), then if you need to make changes to the pages inside the
frames, any variables defi ned in the frameset page will retain their value. This provides a very
useful means of holding information even when the user is navigating your web site. A further
advantage is that any functions defi ned in the frameset-defi ning page can be called by subse-
quent pages and have to be loaded into the browser only once, making your page's loading faster.
The second subject of this chapter is how you can open up and manipulate new browser windows.
There are plenty of good uses for new windows. For example, you may wish to open up an external
web site in a new window from your web site, but still leave your web site open for the user.
External here means a web site created and maintained by another person or company. Let's
say you have a web site about cars — well, you may wish to have a link to external sites, such
Search WWH ::




Custom Search