问题描述
我正在尝试开发一个简单的插件,该插件在新选项卡中打开一个不同于firefox默认页面的网页.我想在about:config中更改两个默认设置值,但似乎无法通过当前配置来实现.
Hi I'm trying to develop a simple addon which opens a web page different from firefox default page in new tab. I want to change two of the default settings values in about:config, but it seems I cannot achieve this through my current configuration.
我正在使用firefox推荐的插件SDK来开发插件.(使用SDK创建一个简单的附件
I'm using the Add-On SDK recommended by firefox to develop the add-on.(creating a simple add-on using the SDK
通过查看about:config设置,我发现如果将"browser.newtab.url"设置为网页URL,并将"moa.ntab.openInNewTab"从true设置为false,则可以实现此功能.因此,我按照上面的教程进行操作,并添加了./defaults/preferences/pref.js来更改配置.
By looking into the about:config setting, I found that if I set "browser.newtab.url" to the web page url, and "moa.ntab.openInNewTab" from true to false, I can realize such function. So I followed the tutorial above and added ./defaults/preferences/pref.js for changing the config.
我当前的目录如下:
ff-addon
└─ data
└─ defaults
└─ preferences
└─pref.js
└─ lib
└─ main.js
└─ package.json
└─ test
└─ test-main.js
/defaults/preferences目录中的pref.js代码如下:
the pref.js code in the /defaults/preferences directory is as follows:
pref("browser.newtab.url", "http://www.baidu.com");
pref("moa.ntab.openInNewTab", false);
我没有更改main.js中的代码.其代码如下所示:
I did not change the code in main.js. Code of it is shown below:
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var button = buttons.ActionButton({
id: "mozilla-link",
label: "Visit Mozilla",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state) {
tabs.open("http://www.mozilla.org/");
}
我也没有更改package.json中的代码:
I did not change the code in package.json either:
{
"name": "ff-addon",
"title": "ff-addon",
"id": "jid1-mPDAO4AqY5w17w",
"description": "a basic add-on",
"author": "",
"license": "MPL 2.0",
"version": "0.1"
}
能否请您告诉我什么地方出了问题,或者我可以完成这些简单的功能……非常感谢!
Could you please tell me what's wrong or maybe what I can follow in finishing such simple functions... Thank you so much!
推荐答案
如第一个评论所述,请参阅 sdk/preferences/service .
As the first comment says, see the documentation for sdk/preferences/service.
这是一个简单的例子:
var name = "extensions.checkCompatibility.nightly";
require("sdk/preferences/service").set(name, false)
这篇关于Firefox插件开发,如何更改about:config设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!