15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Window Object<br />

Properties<br />

clipboardData<br />

Chapter 2 ✦ Window and Frame Objects (Chapter 16)<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓<br />

Example<br />

See Listings 15-30 and 15-39 (in Chapter 1 of this book) to see how the<br />

clipboardData object is used with a variety of edit-related event handlers.<br />

closed<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

In Listing 16-4, I have created the ultimate cross-platform window opening and<br />

closing sample. It takes into account the lack of the opener property in Navigator 2,<br />

the missing closed property in Navigator 2 and Internet Explorer 3, and it even provides<br />

an ugly but necessary workaround for the inability of Internet Explorer 3 to<br />

gracefully see if a subwindow is still open.<br />

The script begins by initializing a global variable, newWind, which is used to hold<br />

the object reference to the second window. This value needs to be global so that<br />

other functions can reference the window for tasks, such as closing. Another global<br />

variable, isIE3, is a Boolean flag that lets the window closing routines know<br />

whether the visitor is using Internet Explorer 3 (see details about the navigator.<br />

appVersion property in Chapter 28 of the <strong>JavaScript</strong> <strong>Bible</strong>).<br />

For this example, the new window contains some HTML code written dynamically<br />

to it, rather than loading an existing HTML file into it. Therefore, the URL parameter<br />

of the window.open() method is left as an empty string. It is vital, however, to<br />

assign a name in the second parameter to accommodate the Internet Explorer 3<br />

workaround for closing the window. After the new window is opened, an opener<br />

property is assigned to the object if one is not already assigned (this property is<br />

needed only for Navigator 2). Next comes a brief delay to allow Internet Explorer<br />

(especially versions 3 and 4) to catch up with opening the window so that content<br />

129<br />

windowObject.closed

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!