Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

preferences

The preferences class simplifies the access to the nsIPrefBranch XPCOM interface and let you read and write preferences.

Attributes

Attribute Type Description
branch nsIPrefBranch Instance which can be used for a more detailed access.

Methods

clearUserPref()

Removes the user-defined preference with the given name.

clearUserPref(
  in string prefName
);
Parameters
prefName
Name of the preference to remove.

getPref()

Retrieves the value of the given preference. The estimated type will be the same as for the defaultValue parameter.

[boolean|number|string] getPref(
  in string prefName,
  in [boolean|number|string] defaultValue
);
Parameters
prefName
Name of the preference which value has to be retrieved.
defaultValue
The parameter's type will be used to guess the preference type. Use it to set a default value if the preference cannot be found.
Return value

The current value of the preference. Possible types are boolean, number, and string.

setPref()

Set the value of the preferences with the given name.

setPref(
  in string prefName,
  in mixed value
);
Parameters
prefName
Name of the preference to set the new value.
value
The new value to be set. Possible types are boolean, number, and string.

Examples

The example below shows how the value of a preference can be updated and read. Finally the user defined value is deleted.

var RELATIVE_ROOT = '../../shared-modules';
var MODULE_REQUIRES = ['PrefsAPI'];

var setupModule = function(module) {
  controller = mozmill.getBrowserController();
}

var testPreferences = function(module) {
  var prefName = "dom.disable_open_during_load";

  PrefsAPI.preferences.setPref(prefName, true);
  controller.window.alert(PrefsAPI.preferences.getPref(prefName, false));  

  PrefsAPI.preferences.clearUserPref(prefName);
}

Document Tags and Contributors

 Contributors to this page: Sheppy, Whimboo
 Last updated by: Sheppy,