Java Reference
In-Depth Information
Figure 8-6
Click the links in either frame to navigate to a new location. For example, click the Page C link in the
right frame, then the Page D link in the left frame. Click the left frame's List Pages Visited button and
you'll see that ch08_examp2_c.htm and ch08_examp2_d.htm have been added to the list.
Normally when a new page is loaded, any variables and their values in the previous page are lost, but
when using frameset pages as modules, it does not matter which page is loaded into each frame — the
top frame remains loaded and its variables keep their values. What you are seeing in this example is
that, regardless of which page is loaded in each frame, some global variable in the top frame is keeping
track of the pages that have been viewed and the top frame's variables and functions can be accessed by
any page loaded into either frame.
There are restrictions when the pages you load into the frames are from external sources — more on
this later in the chapter.
Let's fi rst look at the JavaScript in ch08_examp2.htm , which is the frameset-defi ning page. The head of
the page contains a script block. The fi rst thing in this script block is the declaration of the pagesVisited
variable, and set it to reference a new Array object. In the array, you'll be storing the fi le name of each
page visited as the user navigates the site.
var pagesVisited = new Array();
You then have two functions. The fi rst of the two functions, returnPagesVisited(), does what its name
suggests — it returns a string containing a message and a list of each of the pages visited. It does this by
looping through the pagesVisited array, building up the message string inside the returnValue vari-
able, which is then returned to the calling function.
Search WWH ::




Custom Search