firefox - Firefox:如何使用附加SDK(Jetpack)添加/修改工具栏

标签 firefox firefox-addon toolbar firefox-addon-sdk

因此,我已经多次浏览了附加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/

相关文章:

javascript - 在 url 的请求参数中传递 "#"哈希符号在 Firefox 中不起作用

firefox - 使用插件或扩展禁用单个 javascript 文件

javascript - 从 firefox 插件公开 js 变量

c# - WPF工具栏在调整大小时消失

android - 使用 Android 导航组件拦截返回导航

selenium - 无法创建 selenium.NewRemote

Firefox 不显示数据 URI SVG

css - 固定 div 中的图像 - 有趣的 Firefox 行为

android - 如何更改工具栏中 AppCompatSpinner 的文本颜色?

javascript - 无需用户干预,在 chrome 或 firefox 扩展中使用 Javascript 上传文件