You are here: Reference > JavaScript > client-side > browser > objects > bar objects

Bar objects

The following bar objects are accessible:
Properties Support Description
window.directories
Returns a reference to the directories toolbar.
window.locationbar
Returns a reference to the locationbar object.
window.menubar
Returns a reference to the menubar object.
window.personalbar
Returns a reference to the personalbar object.
window.scrollbars
Returns a reference to the scrollbar object.
window.statusbar
Returns a reference to the statusbar object.
window.toolbar
Returns a reference to the toolbar object.
The base interface, through which you can add new functionalities to all bar objects, is the BarProp interface.

Possible members:

Only the visibility of these objects can be changed from JavaScript.
visible
Sets or retrieves a Boolean value that indicates whether the current bar object is visible or not. This property is read-only in Safari and Google Chrome. In Firefox, the UniversalBrowserWrite privilege is required to modify the value of this property.
Boolean. One of the following values:
true
The bar object is currently visible.
false
The bar object is currently not visible.

Example 1:

This example dumps the visibility of bar objects:
<head>
    <script type="text/javascript">
        function GetBarsInfo () {
            var info = document.getElementById ("info");
            if (window.directories) {
                var vis = window.directories.visible ? "visible" : "not visible";
                info.innerHTML += "Directories Bar: " + vis + "<br />";
            }
            if (window.locationbar) {
                var vis = window.locationbar.visible ? "visible" : "not visible";
                info.innerHTML += "Location Bar: " + vis + "<br />";
            }
            if (window.menubar) {
                var vis = window.menubar.visible ? "visible" : "not visible";
                info.innerHTML += "Menu Bar: " + vis + "<br />";
            }
            if (window.personalbar) {
                var vis = window.personalbar.visible ? "visible" : "not visible";
                info.innerHTML += "Personal Bar: " + vis + "<br />";
            }
            if (window.scrollbars) {
                var vis = window.scrollbars.visible ? "visible" : "not visible";
                info.innerHTML += "Scrollbars: " + vis + "<br />";
            }
            if (window.statusbar) {
                var vis = window.statusbar.visible ? "visible" : "not visible";
                info.innerHTML += "Status Bar: " + vis + "<br />";
            }
            if (window.toolbar) {
                var vis = window.toolbar.visible ? "visible" : "not visible";
                info.innerHTML += "Tool Bar: " + vis + "<br />";
            }
        }
    </script>
</head>
<body onload="GetBarsInfo ()">
    <div id="info"></div>
</body>
Did you find this example helpful? yes no

Example 2:

This example toggles the visibility of the Location Bar:
<head>
    <script type="text/javascript">
        function ToggleLocationBar () {
            if (window.locationbar) {   // Firefox, Google Chrome and Safari

                    // UniversalBrowserWrite privilege is required in Firefox
                try {
                    if (window.netscape && netscape.security) { // Firefox
                        netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserWrite");
                    }
                }
                catch (e) {
                    alert ("UniversalBrowserWrite privilege is required in Firefox!");
                    return;
                }

                window.locationbar.visible = !window.locationbar.visible;   // only works in Firefox
            }
            else {
                alert ("Your browser does not support this example!");
            }
        }
    </script>
</head>
<body>
    <button onclick="ToggleLocationBar ();">Show/Hide the Location Bar</button>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content