Firefox扩展的工具栏图标

时间:2013-09-22 10:03:14

标签: firefox firefox-addon toolbar

我有一个旧的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);

1 个答案:

答案 0 :(得分:2)

您最可以向导航栏添加图标。这是我使用的代码:

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("nav-bar","YOURBUTTONID");

请记住,您必须在BrowserToolbarPalette

中加入“YOURBUTTONID”
<toolbarpalette id="BrowserToolbarPalette">
    <toolbarbutton id="YOURBUTTONID"
                   image='...'
                   class="..."
                   oncommand="..."
                   tooltiptext="">

    </toolbarbutton>
</toolbarpalette>

参考:Toolbar - Code snippets

相关问题