93Chapter 8Window and Document (Web site templates) Objects In Listing 8-3,

93Chapter 8Window and Document Objects

In Listing 8-3, the situation is a bit more complex because the script generates a subwindowto which is written an entirely script-generated document. To keep the reference to the newwindow alive across both functions, the newWindowvariable is declared as a global variable. As soon as the page loads, the onloadevent handler invokes the makeNewWindow()function. This function generates a blank subwindow. I added a property to the third parameter of thewindow.open()method that instructs the status bar of the subwindow to appear. A button in the page invokes the subWrite()method. The first task it performs is to checkthe closedproperty of the subwindow. This property (which exists only in newer browserversions) returns trueif the referenced window is closed. If that s the case (if the user manu- ally closed the window), the function invokes the makeNewWindow()function again to reopenthat window. With the window open, new content is assembled as a string variable. As with Listing 8-2, thecontent is written in one blast (although that isn t necessary for a separate window), followedby a close()method. But notice an important difference: both the write()and close() methods explicitly specify the subwindow. Listing 8-3:Using document.write() on Another Window