Using Settings in Firefox

How do I access user preferences in Firefox? I have the following code:

var control = document.getElementById(control_id);
if (control) {
    control.setAttribute('color', nsPreferences.copyUnicharPref(prefstr, default_val));
}

But when I run this, I get the following:

Error: nsPreferences is not defined
Source file: chrome://backgroundtoggle/content/options.xul
Line: 9

I'm having trouble processing Mozilla documentation. How to do as I want?

+3
source share
1 answer

It looks like you need to include nsUserSettings.jsin your file .xul:

<script type="application/x-javascript" src="chrome://global/content/nsUserSettings.js" />

It is defined here nsUserPreferences.

See here for an example options.xul. The tag scriptmust be the first child prefwindowto make sure that it loads before your own code.


Additional Information

, Firefox. , mozilla.org mozilla.org, . , , ? "", . , , "Next" "Previous" .

+3

Source: https://habr.com/ru/post/1698736/


All Articles