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.

134<br />

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

directories<br />

locationbar<br />

menubar<br />

personalbar<br />

scrollbars<br />

statusbar<br />

toolbar<br />

windowObject.directories<br />

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

Compatibility ✓ ✓<br />

Example<br />

In Listing 16-6, you can experiment with the look of a browser window with any<br />

of the chrome elements turned on and off. To run this script, you must either sign<br />

the scripts or turn on codebase principals (see Chapter 46 of the <strong>JavaScript</strong> <strong>Bible</strong>).<br />

Java must also be enabled to use the signed script statements.<br />

As the page loads, it stores the current state of each chrome element. One button<br />

for each chrome element triggers the toggleBar() function. This function<br />

inverts the visible property for the chrome object passed as a parameter to the<br />

function. Finally, the Restore button returns visibility to their original settings.<br />

Notice that the restore() function is also called by the onUnload event handler<br />

for the document. Also, if you load this example into NN6, non-fatal script errors<br />

occur when the scrollbars are turned on or off.<br />

Listing 16-6: Controlling Window Chrome<br />

<br />

<br />

Bars Bars Bars<br />

<br />

// store original outer dimensions as page loads<br />

var originalLocationbar = window.locationbar.visible<br />

var originalMenubar = window.menubar.visible<br />

var originalPersonalbar = window.personalbar.visible<br />

var originalScrollbars = window.scrollbars.visible<br />

var originalStatusbar = window.statusbar.visible<br />

var originalToolbar = window.toolbar.visible<br />

// generic function to set inner dimensions<br />

function toggleBar(bar) {<br />

netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserWrite”)<br />

bar.visible = !bar.visible<br />

netscape.security.PrivilegeManager.revertPrivilege(“UniversalBrowserWrite”)<br />

}

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

Saved successfully!

Ooh no, something went wrong!