You are here: Reference > JavaScript > client-side > browser > methods > preference (navigator)

preference method (navigator)

Browser support:
Gets or sets a user preference. Only available in privileged code.
Reading the preferences requires the UniversalPreferencesRead privilege, modifying the preferences requires the UniversalPreferencesWrite privilege.

Syntax:

object.preference (name [, value]);
You can find the related objects in the Supported by objects section below.

Parameters:

name
Required. String that specifies the name of the preference.
value
Optional. String that specifies the value of the preference.

Return value:

If the value parameter is not specified, the preference method returns the value of the preference specified by the name parameter, else the returned value is undefined.

Example HTML code 1:

This example illustrates the use of the preference method:
<head>
    <script type="text/javascript">
        function SetHomePage () {
            if (navigator.preference) {
                    // UniversalPreferencesRead privilege is required in Firefox
                try {
                    if (window.netscape && netscape.security) { // Firefox
                        netscape.security.PrivilegeManager.enablePrivilege ("UniversalPreferencesRead");
                    }
                }
                catch (e) {
                    alert ("UniversalPreferencesRead privilege is required in Firefox!");
                    return;
                }

                var homePage = navigator.preference ('browser.startup.homepage');

                if (homePage != 'http://help.dottoro.com/') {
                    var confRet = window.confirm ("Your Home Page settings will be modified! Do you want to continue the operation?");
                    if (confRet) {
                            // UniversalPreferencesWrite privilege is required in Firefox
                        try {
                            if (window.netscape && netscape.security) { // Firefox
                                netscape.security.PrivilegeManager.enablePrivilege ("UniversalPreferencesWrite");
                            }
                        }
                        catch (e) {
                            alert ("UniversalPreferencesWrite privilege is required in Firefox!");
                            return;
                        }

                        navigator.preference ('browser.startup.homepage', 'http://help.dottoro.com/');

                        alert ("Your Home Page is 'http://help.dottoro.com/' now!");
                    }
                }
                else {
                    alert ("No need to modify your Home Page.");
                }
            }
            else {
                alert ("Your browser does not support this example!");
            }
        }
    </script>
</head>
<body>
    <button onclick="SetHomePage ();">Set my Home Page to help.dottoro.com!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content