preference element

By Opera Software

From Opera 15 onward, Opera 11 & 12’s extension format is no longer supported, and instead, we’ve switched to Chromium’s extension model. Check out our new documentation for developing extensions for Opera 15 and higher and start building your own extensions.

Description

The <preference> element allows for preferences to be declared by the developer. Using this, a key-value pair is stored in a persistent manner and is initiated the first time the extension is started. Preferences can then be accessed at runtime via the widget.preferences object in the background process or in any page from within the extension (see the markup example below).

The following attributes are associated with it.

  • name: Denotes a name for this preference
  • value: Denotes a value for this preference
  • readonly: Indicates whether it can be overwritten at runtime or not; it is a boolean, with valid values as "true" or "false"

Example

An example of this could be the following:

<widget xmlns="http://www.w3.org/ns/widgets">
  <preference name     = "api-key"
    value    = "abcd123456"
    readonly = "true"/>
</widget>

Then, in the background process:

//
// background.js
//

//gets the value the preference in the config.xml
var apiKey = widget.preferences["api-key"];

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

No new comments accepted.