JavaScript Editor JavaScript Validator     JavaScript Editor 



Team LiB
Previous Section Next Section

Chapter 7: Windows and Frames

Overview

Until now, the pages we have been looking at have just been single pages. However, many web applications make use of 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 websites 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 we can keep common variables and functions in one place but use them from many places. We'll start this chapter by looking at how we can script across such frames.

Apart from having a frames-based website, a number of other good reasons exist for wanting to access variables and functions in another frame. Two important reasons are making your code modular and having the ability to maintain information between pages.

What do we mean by modular? In other programming languages, like Visual Basic, you can create a module, that is, an area to hold general functions and variables, and reuse it from different places in your program. Well, when using frames we can put all of our general functions and variables into one area, such as the top frame, which we can think of as our code module. Then we can call the functions repeatedly from different pages and different frames.

If we put the general functions and variables in a page that defines the frames that it contains (that is, a frameset-defining page), then if we need to make changes to the pages inside the frames, any variables defined in the frameset page will retain their value. This provides a very useful way of holding information even when the user is navigating our website. A further advantage is that any functions defined in the frameset-defining page can be called by subsequent pages and only have to be loaded into the browser once, making our 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" website in a new window from your website, but leave your website still open for the user. By external, I mean a website created and maintained by another person or company. Let's say you had a website about cars—well, you may wish to have a link to external sites, such as manufacturing websites (for example, Ford or General Motors websites). Perhaps even more useful is using small windows as dialog boxes, which you can use to obtain information from the user. Just as you can script between frames, you can do similar things between certain windows. We'll find out how later in the chapter, but let's start by looking at scripting between frames.


Team LiB
Previous Section Next Section


JavaScript Editor JavaScript Validator     JavaScript Editor


©