15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

398<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

<strong>Examples</strong> Highlights<br />

✦ Listing 28-1 provides numerous functions that examine navigator object<br />

properties. The functions examples are provided more as demonstrations of<br />

specific values your scripts may need to look for, rather than as some super<br />

“browser sniffer.” Determining specific IE versions is a bit tricky, so observe<br />

how to go about it by way of the navigator.appVersion property.<br />

✦ NN4+ provides access to browser preferences via the navigator.<br />

preference() method, as shown in Listing 28-2. To implement this feature in<br />

a production page, you’ll need to use signed scripts.<br />

✦ Experiment with the screen.availLeft and screen.availTop properties in<br />

NN4+, especially in the Windows environment to see how the taskbar affects<br />

these property values.<br />

✦ For IE4+/Windows, follow the sequence of examples for the userProfile<br />

object’s methods to see how scripts can read user profile fields.<br />

clientInformation Object (IE4+)<br />

and navigator Object (All)<br />

Properties<br />

appCodeName<br />

appName<br />

appVersion<br />

userAgent<br />

navigator.appCodeName<br />

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

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

Listing 28-1 provides a number of reusable functions that your scripts can<br />

employ to determine a variety of information about the currently running browser.<br />

This is not intended in any way to be an all-inclusive browser-sniffing routine;<br />

instead, I offer samples of how to extract information from the key navigator<br />

properties to determine various browser conditions.<br />

All functions in Listing 28-1 return a Boolean value inline with the pseudoquestion<br />

presented in the function’s name. For example, the isWindows() function<br />

returns true if the browser is any type of Windows browser; otherwise, it returns<br />

false. (In Internet Explorer 3, the values are 0 for false and -1 for true, but those

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

Saved successfully!

Ooh no, something went wrong!