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 wading through the Mozilla documentation. How do I make this do what I want?
It looks like you need to include
nsUserSettings.jsin your.xulfile:This is where
nsUserPreferencesis defined.See here for an example
options.xulfile. Thescripttag should be the first child element ofprefwindowto ensure it gets loaded before your own code does.Additional Information
This looks like a decent tutorial on how to write Firefox extensions. It seems to do a good job of consolidating all the relevant information on mozilla.org in one place, and contains links to mozilla.org when you need more details on a topic being covered. I do wish the navigation was a little better, but what can you do? Use the navigation pane on the left-hand side and click Tutorial to get started. You have to move through each section using the navigation pane, which took me few seconds to figure out, as I was looking for ‘Next’ and ‘Previous’ links on the page.