因此,我已经多次浏览了附加SDK的文档,没有哪里可以看到如何创建工具栏或修改现有工具栏的方法。他们有一个有关创建附加栏图标的教程,但是那不是我想要的。附加SDK是否支持此功能?如果可以,有人可以将我链接到示例/教程。
最佳答案
这对我有用:
var data = require("self").data;
var {Cc, Ci} = require("chrome");
var mediator = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
exports.main = function(options, callbacks) {
addToolbarButton();
// other stuff
};
function addToolbarButton() {
var document = mediator.getMostRecentWindow("navigator:browser").document;
var navBar = document.getElementById("nav-bar");
if (!navBar) {
return;
}
var btn = document.createElement("toolbarbutton");
btn.setAttribute('type', 'button');
btn.setAttribute('class', 'toolbarbutton-1');
btn.setAttribute('image', data.url('img/icon16.png')); // path is relative to data folder
btn.setAttribute('orient', 'horizontal');
btn.setAttribute('label', 'My App');
btn.addEventListener('click', function() {
// use tabs.activeTab.attach() to execute scripts in the context of the browser tab
console.log('clicked');
}, false)
navBar.appendChild(btn);
}
关于firefox - Firefox:如何使用附加SDK(Jetpack)添加/修改工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5572632/