• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Frames, Frames, and More Frames > Storing Information in Frames

Storing Information in Frames

In situations similar to that in the previous example, you can also keep track of useful information across frames, by storing the variables in the permanent frame page. Figure 4.11 shows how many times a user has visited each content page this session. Once again, scripts are needed in multiple frames, and those frames are loaded by the frameset in Script 4.22.

Figure 4.11. The JavaScript says that you have viewed Page 2 three times in this session.

Script 4.22. Start off by loading in the frameset.

Script 4.23. Initialize the JavaScript variables in the navigation frame.

Script 4.24. Add one to the JavaScript page counter and show the result.

To keep a count of page visits:

								page1Count = 0
								page2Count = 0
								page3Count = 0

In Script 4.23, in the navigation frame, initialize the three variables you want to keep track of, one for each content page.


In the header area of Script 4.24, in the content frame, you add one to the counter page1Count, located in the navigation frame. Use a different counter variable for each content page, as shown in Scripts 4.25 and 4.26.

								document.write (parent.left.page1Count)

In the body area of Script 4.24, you use the page1Count variable, which displays the number of times that a visitor has visited this page in this session.

Script 4.25. This script increments the page 2 counter by one.

Script 4.26. The page 3 counter gets incremented with this script.

Script 4.27. Start off by loading the frameset.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint