371Chapter 16Window and Frame ObjectsYou cannot use the (Dedicated web hosting)
371Chapter 16Window and Frame ObjectsYou cannot use the clipboardDataobject to transfer data between pages that originate fromdifferent domains or arrive via different protocols (httpversus https). ExampleSee Listings 15-30 and 15-39 to see how the clipboardDataobject is used with a variety ofedit-related event handlers. Related Items:event.dataTransferproperty; onbeforecopy, onBeforeCut, onbeforepaste, oncopy, oncut, onpasteevent handlers. closedValue:Boolean.Read-OnlyCompatibility:WinIE4+, MacIE4+, NN3+, Moz1+, Safari1+ When you create a subwindow with the window.open()method, you may need to accessobject properties from that subwindow, such as setting the value of a text field. Access to thesubwindow is via the windowobject reference that is returned by the window.open() method, as in the following code fragment: var newWind = window.open( someURL.html , subWind ); … newWind.document.entryForm.ZIP.value = 00000 ; In this example, the newWindvariable is not linked live to the window, but is only a refer- ence to that window. If the user should close the window, the newWindvariable still containsthe reference to the now missing window. Thus, any script reference to an object in that miss- ing window will likely cause a script error. What you need to know before accessing items inasubwindow is whether the window is still open. The closedproperty returns trueif the windowobject has been closed either by script orbythe user. Any time you have a script statement that can be triggered after the user has anopportunity to close the window, test for the closedproperty before executing thatstatement. ExampleIn Listing 16-4, I have created a basic window opening and closing example. The script beginsby initializing a global variable, newWind, which is used to hold the object reference to thesecond window. This value needs to be global so that other functions can reference the win- dow for tasks, such as closing. For this example, the new window contains some HTML code written dynamically to it, ratherthan loading an existing HTML file into it. Therefore, the URL parameter of the window.open() method is left as an empty string. Next comes a brief delay to allow Internet Explorer (espe- cially versions 3 and 4) to catch up with opening the window so that content can be writtento it. The delay (using the setTimeout()method described later in this chapter) invokes thefinishNewWindow()function, which uses the global newWindvariable to reference the win- dow for writing. The document.close()method closes writing to the document a differentkind of close than a window close. A separate function, closeWindow(), is responsible forclosing the subwindow. As a final test, an ifcondition looks at two conditions: 1) if the windowobject has ever beeninitialized with a value other than null(in case you click the window closing button beforeever having created the new window) and 2) if the window s closedproperty is nullorfalse. If either condition is true, the close()method is sent to the second window. windowObject.closed