【问题标题】:Toolbar icon for Firefox extensionFirefox 扩展的工具栏图标
【发布时间】:2013-09-22 10:03:14
【问题描述】:

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

【问题讨论】:

  • 标准 addons.mozilla.org 拒绝响应:您的插件使用户无法永久删除其工具栏按钮,这是我们不允许的。在第一次运行时插入工具栏按钮是可以的,并且建议您在每次启动时都这样做,或者无法移动或删除它。
  • 你成功了吗?

标签: firefox firefox-addon toolbar


【解决方案1】:

您绝对可以在导航栏上添加一个图标。这是我使用的代码:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多