• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
B2G OS
  1. MDN
  2. Archive of obsolete content
  3. B2G OS
  4. B2G OS APIs
  5. SettingsManager
  6. SettingsManager.addObserver()

SettingsManager.addObserver()

In This Article
  1. Summary
  2. Syntax
    1. Parameters
  3. Example
  4. Specification
  5. See also

This API is available on Firefox OS for internal applications only.

Summary

Sets up a callback function to be notified when a specific setting's value changes.

Note: If you want to listen for and react to any change to any setting, you can directly set a callback function using the onsettingchange property of the SettingsManager object.

Syntax

SettingsManager.addObserver(settingName, callback);

Parameters

settingName
A string specifying the name of the setting to observe. The exact list of possible strings is device-dependent. Each Gaia build can have its own list of settings. For an up-to-date list of those strings, take a look at the Gaia source code.
callback
The function to be called each time the value of the setting is changed. This function will receive as input a MozSettingsEvent providing details about the change that occurred.

Example

// Listen to changes on the wifi.enabled setting
navigator.mozSettings.addObserver('wifi.enabled', function (event) {
  console.log('wifi.enabled: ' + event.settingValue);
});

Specification

Not part of any specification yet; however, this API will be discussed at W3C as part of the System Applications Working Group.

See also

  • SettingsManager
  • SettingsLock
  • Settings API

Document Tags and Contributors

Tags: 
  • API
  • B2G
  • Firefox OS
  • Method
  • Non-standard
  • Reference
  • Référence
  • Settings
 Contributors to this page: chrisdavidmills, fscholz, MHasan, kscarfone, stasm, Sheppy, Jeremie
 Last updated by: chrisdavidmills, Feb 27, 2017, 2:07:33 AM
See also
  1. Settings API
  2. Archive
  3. Events
    1. settingchange
  4. Related pages for Settings API
    1. MozSettingsEvent
    2. SettingsLock
    3. SettingsManager