I’m having a trouble with a statusbar’s label value, which is set by a function. I have to save this value before the user closes the browser, recover it and run the function again.
the only way i think it’s possible is using cookies.
I’ve found 2 interesting codes in MDN:
For setting cookies:
var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var cookieUri = ios.newURI("http://www.yourplacewhereyouwanttosetthecookie.com/", null, null);
var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
cookieSvc.setCookieString(cookieUri, null, "your_key=your_value;", null);
and for reading them:
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newURI("http://www.google.com/", null, null);
var cookieSvc = Components.classes["@mozilla.org/cookieService;1"]
.getService(Components.interfaces.nsICookieService);
var cookie = cookieSvc.getCookieString(uri, null);
the problem is that i can’t understand this. where i can put my statusbar’s label? what does “your_key=your_value” mean? how i can recover this value using the reading code? why i have to set an internet address at “newURI”?
i’m sorry, but i’m still learning it 🙂 . will be glad if i get some help.
Thanks a lot!
It’d probably be better to use preferences to save that info. Add a preference to your default preferences js file e.g.
pref("extensions.myextension.thelabelvalue", "whatever");https://developer.mozilla.org/en/Building_an_Extension#Defaults_Files
Then add
Components.utils.import("resource://gre/modules/Services.jsm");to the top of your main javscript file https://developer.mozilla.org/en/JavaScript_code_modules/Services.jsmand you can then use the set/get preference methods listed here: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPrefBranch
e.g.