FF extension: saving a value in preferences and retrieving in the js file

Posted by encryptor on Stack Overflow See other posts from Stack Overflow or by encryptor
Published on 2010-05-04T11:43:47Z Indexed on 2010/05/04 11:48 UTC
Read the original article Hit count: 270

I am making an extension which should take a link as the user input only once. Then the entire extension keeps using that link on various functions in the JS file. When the user changes it, the value accessed by the js file also changes accordingly. I am using the following but it does not work for me

var pref_manager = Components.classes["@mozilla.org/preferencesservice;1"].getService(Components.interfaces.nsIPrefService)

function setInstance(){

if (pref_manager.prefHasUserValue("myvar")) { instance = pref_manager.getString("myvar");

alert(instance);

} if(instance == null){

instance = prompt("Please enter webcenter host and port");

// Setting the value

pref_manager.setString("myvar", instance);

}

} instance is the global variable in which i take the user input. The alert (instance) does not show up, which means there is some problem by the way i am saving the pref or extracting it. Can someone please help me with this. I have never worked with preferences before. so even if there are minor problems i might not be able to figure out.

© Stack Overflow or respective owner

Related posts about firefox

Related posts about xul