Here's another capability of the Netscape Navigatoryou can customize the appearance of this browser using window properties. To do that, you can use the locationbar , menubar , personalbar , scrollbars , statusbar , and toolbar properties you see in Table 7.2. These properties control whether the corresponding bars display. If you set the menubar property to false, for example, the menu bar disappears. Here's an example that will let you toggle the various bars of the Netscape Navigator on and off just by toggling check boxes (which we'll see in Chapter 12, "Working with Forms, Buttons, Check Boxes, and Radio Buttons"). To avoid letting malicious scripts configure the browser without your consent , scripts such as these need special security privileges before working with these bars, and I'll use the netscape.security.PrivilegeManager.enablePrivilege method to set the needed security privilege here, and then revert back later to normal privilege levels with the netscape.security.PrivilegeManager .revertPrivilege method. The Netscape Navigator will check with you before giving higher privileges to the script. Here's what the code looks like: (Listing 07-06.html on the web site)<HTML> <HEAD> <TITLE>Toggling Navigator Bars</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function handleBar() { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite") window.locationbar.visible = document.form1.check01.checked window.menubar.visible = document.form1.check02.checked window.personalbar.visible = document.form1.check03.checked window.scrollbars.visible = document.form1.check04.checked window.statusbar.visible = document.form1.check05.checked window.toolbar.visible = document.form1.check06.checked netscape.security.PrivilegeManager.revertPrivilege("UniversalBrowserWrite") } // --> </SCRIPT> </HEAD> <BODY> <H1>Toggling Navigator Bars</H1> <FORM NAME="form1"> <INPUT TYPE="CHECKBOX" ID="check01" ONCLICK="handleBar()" CHECKED>Location Bar <BR> <INPUT TYPE="CHECKBOX" ID="check02" ONCLICK="handleBar()" CHECKED>Menu Bar <BR> <INPUT TYPE="CHECKBOX" ID="check03" ONCLICK="handleBar()" CHECKED>Personal Bar <BR> <INPUT TYPE="CHECKBOX" ID="check04" ONCLICK="handleBar()" CHECKED>Scrollbars <BR> <INPUT TYPE="CHECKBOX" ID="check05" ONCLICK="handleBar()" CHECKED>Status Bar <BR> <INPUT TYPE="CHECKBOX" ID="check05" ONCLICK="handleBar()" CHECKED>Tool Bar </FORM> </BODY> </HTML> When you click a check box in this document, the browser checks with you to see whether you want to give the script higher privileges with an "Internet Security" dialog box, as you see in Figure 7.6, where I've clicked the menu bar check box. Figure 7.6. Requesting higher privileges in the Netscape Navigator.
If you click Yes in the Internet Security box, the menu bar will disappear, as shown in Figure 7.7. Now we're configuring the Netscape Navigator just by clicking check boxes. Figure 7.7. Removing the menu bar in the Netscape Navigator.
Tip You don't have to check with the user before turning bars on and off when you're displaying a new window, as we'll see in the next chapter. |