Setting Netscape Navigator Preferences


You can use the preference method to set Netscape Navigator preferences , such as whether the browser should warn the user before accepting cookies and what screen colors to use. Netscape lists about 16 pages of preferences and their possible settings currently at http://developer.netscape.com/docs/manuals/communicator/preferences/. Here are a few to give you a sampling:

  • browser.background_color . Sets the default color for page backgrounds. Set to a browser color triplet .

  • browser.cache.disk_cache_size . Sets the size of the web page cache on hard disks.

  • browser.foreground_color . Sets the default color for regular web page text. Set to a browser color triplet.

  • browser.startup.page . Sets what page, if any, the Netscape Navigator should display when it starts.

  • browser.window_rect . Specifies the position and dimensions of the browser window, in pixels.

  • network.cookie.warnAboutCookies . Warns the user before accepting cookies.

For more details and settings, take a look at http://developer.netscape.com/docs/manuals/communicator/preferences/. Here's an example that toggles whether the browser will warn the user before accepting cookies. Note that to set preferences, this script enables and disables the UniversalPreferencesRead and UniversalPreferencesWrite security privileges. The browser will check with the userusing a dialog boxbefore changing this privilege level. Note that this example uses getElementById , which is not supported in NS4; if you want to use that browser, you might change this code to write results to a text field rather than a <DIV> element:

(Listing 10-02.html on the web site)
 <HTML>      <HEAD>          <TITLE>Setting Netscape Navigator Preferences</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  function getPref()   {   netscape.security.PrivilegeManager.enablePrivilege( graphics/ccc.gif "UniversalPreferencesRead")   if(navigator.preference('network.cookie.warnAboutCookies')){   document.getElementById("div1").innerHTML = "Will warn before   accepting cookies."   } else {   document.getElementById("div1").innerHTML = "Will not warn before graphics/ccc.gif accepting cookies."   }   netscape.security.PrivilegeManager.revertPrivilege( graphics/ccc.gif "UniversalPreferencesRead")   }   function warnCookie()   {   netscape.security.PrivilegeManager.enablePrivilege( graphics/ccc.gif "UniversalPreferencesWrite")   navigator.preference('network.cookie.warnAboutCookies', true)   netscape.security.PrivilegeManager.revertPrivilege( graphics/ccc.gif "UniversalPreferencesWrite")   getPref()   }   function noWarnCookie()   {   netscape.security.PrivilegeManager.enablePrivilege( graphics/ccc.gif "UniversalPreferencesWrite")   navigator.preference('network.cookie.warnAboutCookies', false)   netscape.security.PrivilegeManager.revertPrivilege( graphics/ccc.gif "UniversalPreferencesWrite")   getPref()   }  // -->          </SCRIPT>      </HEAD>      <BODY ONLOAD="getPref()">          <H1>Setting Netscape Navigator Preferences</H1>          <FORM>              <INPUT TYPE="BUTTON" NAME="warn" ONCLICK="warnCookie()"                  VALUE="Warn before accepting cookies">              <BR>              <INPUT TYPE="BUTTON" NAME="nowarn" ONCLICK="noWarnCookie()"                  VALUE="Do not warn when accepting cookies">          </FORM>          <BR>          <DIV ID="div1"></DIV>      </BODY>  </HTML> 

You can see the results in the Netscape Navigator in Figure 10.2, where I've changed the default behavior of the browser to warn the user before accepting cookies.

Figure 10.2. Setting Netscape Navigator preferences.

graphics/10fig02.gif



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net