Apache web server for windows - 128Part IIJavaScript TutorialKnowing that navigation from page to

128Part IIJavaScript TutorialKnowing that navigation from page to page in the upper-right frame requires knowledge ofwhich page is currently loaded there, I build some other scripting into both the parent docu- ment and each of the documents that loads into that frame. A global variable calledcurrTitleis defined in the parent document. Its value is an integer indicating which page ofthe sequence (1 through 5) is currently loaded. An onloadevent handler in each of the fivedocuments (named dh1.htm, dh2.htm, dh3.htm, dh4.htm, and dh5.htm) assigns its pagenumber to that parent global variable. This arrangement allows all frames in the frameset toshare that value easily. When a user clicks the right-facing arrow to move to the next page, the goNext()function iscalled. The first statement gets the currTitlevalue from the parent window and assigns it toa local variable: currOffset. An if…elseconstruction tests whether the current pagenumber is less than five. If so, the add-by-value operator adds one to the local variable so Ican use that value in the next two statements. In those next two statements, I adjust the content of the two right frames. Using the parentreference to gain access to both frames, I set the location.hrefproperty of the top-rightframe to the name of the file next in line (by concatenating the number with the surroundingparts of the filename). The second statement sets the location.hashproperty (which con- trols the anchor being navigated to) to the corresponding anchor in the instructionsframe(anchor names help1, help2, help3, help4, and help5). A click of the left-facing arrow reverses the process, subtracting 1 from the current page num- ber (using the subtract-by-value operator) and changing the same frames accordingly. The example shown in Listing 11-1 is one of many ways to script a navigation frame inJavaScript. Whatever methodology you use, much interaction occurs among the frames in theframeset. References for Multiple WindowsIn Chapter 8, you saw how to create a new window and communicate with it by way of thewindowobject reference returned from the window.open()method. In this section, I showyou how one of those subwindows can communicate with objects, functions, and variables inthe window or frame that creates the subwindow. Every windowobject has a property called opener. This property contains a reference to thewindow or frame that held the script whose window.open()statement generated the subwin- dow. For the main browser window and frames therein, this value is null. Because theopenerproperty is a valid window reference, you can use it to begin the reference to items inthe original window just like a script in a child frame uses parentto access items in theparent document. The parent-child terminology doesn t apply to subwindows, however. Listings 11-2 and 11-3 contain documents that work together in separate windows. Listing11-2 displays a button that opens a smaller window and loads Listing 11-3 into it. The mainwindow document also contains a text field that gets filled in when you enter text into a cor- responding field in the subwindow. In the main window document, the newWindow()function generates the new window. Because no other statements in the document require the reference to the new window justopened, the statement does not assign its returned value to any variable. This is an accept- able practice in JavaScript if you don t need the returned value of a function or method.