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.

Chapter 12 ✦ Navigator and Other Environment Objects (Chapter 28)<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) with your IE4+ browser to<br />

compare the values of the three language-related properties running on your computer.<br />

Enter each of the following statements into the top text box:<br />

navigator.browserLanguage<br />

navigator.systemLanguage<br />

navigator.userLanguage<br />

Don’t be surprised if all three properties return the same value.<br />

Methods<br />

preference(name [, val])<br />

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

Compatibility ✓ ✓<br />

Example<br />

The page in Listing 28-2 displays checkboxes for several preference settings, plus<br />

one text box to show a preference setting value for the size of the browser’s disk<br />

cache. To run this script without signing the scripts, turn on codebase principals as<br />

directed in Chapter 46 of the <strong>JavaScript</strong> <strong>Bible</strong>. (The listing file on the CD-ROM does<br />

not employ signed scripts.)<br />

One function reads all the preferences and sets the form control values accordingly.<br />

Another function sets a preference when you click its checkbox. Because of<br />

the interaction among three of the cookie settings, it is easier to have the script<br />

rerun the showPreferences() function after each setting rather than you trying to<br />

manually control the properties of the three checkboxes. Rerunning that function<br />

also helps verify that you set the preference.<br />

Listing 28-2: Reading and Writing Browser Preferences<br />

<br />

<br />

Reading/Writing Browser Preferences<br />

<br />

function setPreference(pref, value) {<br />

netscape.security.PrivilegeManager.enablePrivilege(<br />

“UniversalPreferencesWrite”)<br />

navigator.preference(pref, value)<br />

netscape.security.PrivilegeManager.revertPrivilege(<br />

“UniversalPreferencesWrite”)<br />

showPreferences()<br />

}<br />

Continued<br />

405<br />

navigator.preference()

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

Saved successfully!

Ooh no, something went wrong!