如何在Firefox扩展中将首选项重置为以前的值?

时间:2014-03-07 21:25:47

标签: firefox-addon

我有一个扩展程序,允许用户更改主页和新标签页。我是通过更改某些首选项的值来实现的(例如browser.startup.homepage,browser.newtab.url)。

我想在用户卸载扩展程序时将这些首选项的值重置为以前的值(非默认值)。

如何将首选项重置为之前的值?

感谢。

1 个答案:

答案 0 :(得分:0)

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
const ps = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
ps.clearUserPref('full.path.to.pref.here');

注意:此复位优先于默认值,如果未设置默认值,则删除pref。