CD-254 Part VI . Appendixes variable, isIE3, is (Apache web server)
Saturday, October 27th, 2007CD-254 Part VI . Appendixes variable, isIE3, is a Boolean flag that lets the window closing routines know whether the visitor is using Internet Explorer 3 (see details about the navigator.appVersion property in Chapter 28). For this example, the new window contains some HTML code written dynamically to it, rather than loading an existing HTML file into it. Therefore, the URL parameter of the window.open() method is left as an empty string. It is vital, however, to assign a name in the second parameter to accommodate the Internet Explorer 3 workaround for closing the window. After the new window is opened, an opener property is assigned to the object if one is not already assigned (this property is needed only for Navigator 2). Next comes a brief delay to allow Internet Explorer (especially versions 3 and 4) to catch up with opening the window so that content can be written to it. The delay (using the setTimeout() method described later in this chapter) invokes the finishNewWindow() function, which uses the global newWind variable to reference the window for writing. The document.close() method closes writing to the document a different kind of close than a window close. A separate function, closeWindow(), is responsible for closing the subwindow. To accommodate Internet Explorer 3, the script appears to create another window with the same characteristics as the one opened earlier in the script. This is the trick: If the earlier window exists (with exactly the same parameters and a name other than an empty string), Internet Explorer does not create a new window even with the window.open()method executing in plain sight. To the user, nothing unusual appears on the screen. Only if the user has closed the subwindow do things look weird for Internet Explorer 3 users. The window.open()method momentarily creates that subwindow. This subwindow is necessary because a living window object must be available for the upcoming test of window existence (Internet Explorer 3 displays a script error if you try to address a missing window, while NN2+ and IE4+ simply return friendly null values). As a final test, an if condition looks at two conditions: 1) if the window object has ever been initialized with a value other than null (in case you click the window closing button before ever having created the new window) and 2) if the window s closed property is null or false. If either condition is true, the close() method is sent to the second window. Listing 16-4: Checking Before Closing a Window