« Documentation Home

widget.preferences

This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.

For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.

Description:

This readonly attribute implements a HTML5 DOM Storage interface that allows read/write access to the name and values of any preference elements declared in the configuration document. Read more about how to make use of widget.preferences in the options page for your extension.

Example:

HTML section of options.html:

<!doctype html>

...

<fieldset id="prefs-form">
<legend>Game Options</legend>
  <label>Volume:  <input type="range" min="0" max="100" name="volume"/> </label>
  <label>Difficulty:  <input type="range" min="0" max="100" name="difficulty"/> </label>
  <input type="button" value="Save" onclick="savePrefs()"/>
  <input type="button" value="load" onclick="loadPrefs()"/>
</fieldset>

...

JavaScript section of options.html:

<script>
var form   = document.getElementById("prefs-form");
var fields = form.querySelectorAll("input[type='range']");

// Get the preference values from the widget object
function loadPrefs() {
  for (var i = 0; i < fields.length; i++) {
    var field = fields[i];
    if (typeof widget.preferences[field.name] !== "undefined") {
      field.value = widget.preferences.getItem(field.name);
    }
  }
}

// Set the preference values for each field
function savePrefs () {
  for (var i = 0; i < fields.length; i++) {
    var field = fields[i];
    widget.preferences.setItem(field.name, field.value);
  }
}
</script>