Firefox扩展的工具栏图标

Firefox扩展的工具栏图标,firefox,firefox-addon,toolbar,Firefox,Firefox Addon,Toolbar,我有一个旧的FF扩展,我想更新。问题是扩展工具栏不再位于地址栏旁边。我已经搜索了很多,脚本似乎是唯一的方法,但我没有找到一种方法让它工作 例如,我不知道如何获得导航条的引用 我试过这个,但没有成功: var navBar = document.getElementById('nav-bar'); if (!navBar) { return; } var btn = document.createElement('toolbarbutton');

我有一个旧的FF扩展,我想更新。问题是扩展工具栏不再位于地址栏旁边。我已经搜索了很多,脚本似乎是唯一的方法,但我没有找到一种方法让它工作

例如,我不知道如何获得导航条的引用

我试过这个,但没有成功:

    var navBar = document.getElementById('nav-bar');
    if (!navBar) {
        return;
    }
    var btn = document.createElement('toolbarbutton');  
    btn.setAttribute('id', 'mybutton-id');
    btn.setAttribute('type', 'button');
    btn.setAttribute('class', 'toolbarbutton-1');
    btn.setAttribute('image', data.url('bulb.png'));
    btn.setAttribute('orient', 'horizontal');
    btn.setAttribute('label', 'My Button');
    navBar.appendChild(btn);

你完全可以在导航栏上添加一个图标。以下是我使用的代码:

function installButton(toolbarId, id, afterId) {
    if (!document.getElementById(id)) {
        var toolbar = document.getElementById(toolbarId);

        if (toolbar) {
            // If no afterId is given, then append the item to the toolbar
            var before = null;
            if (afterId) {
                var elem = document.getElementById(afterId);
                if (elem && elem.parentNode == toolbar)
                    before = elem.nextElementSibling;
            }


            toolbar.insertItem(id, before);
            toolbar.setAttribute("currentset", toolbar.currentSet);
            document.persist(toolbar.id, "currentset");

            if (toolbarId == "addon-bar")
                toolbar.collapsed = false;
        }

    }
}
您可以通过以下方式进行调用:

installButton(“导航栏”、“您的按钮”)

请记住,您必须在
BrowserToolbarPalette

<toolbarpalette id="BrowserToolbarPalette">
    <toolbarbutton id="YOURBUTTONID"
                   image='...'
                   class="..."
                   oncommand="..."
                   tooltiptext="">

    </toolbarbutton>
</toolbarpalette>


参考资料:

Standard addons.mozilla.org拒绝响应:您的插件使用户无法永久删除其工具栏按钮,这是我们不允许的。在第一次运行时插入工具栏按钮是可以的,并且是推荐的,但在每次启动时都要这样做,或者使工具栏按钮无法移动或删除,则不是。您是否成功地使其工作?