2013-09-22 193 views
1

我有一箇舊的FF擴展,我想更新。問題是擴展工具欄不再放置在地址欄旁邊。我搜索了很多,腳本似乎是唯一的方法,但我沒有找到一種方法來實現它。Firefox擴展的工具欄圖標

例如,我不知道怎麼去的導航欄的參考。

我想這一點,但沒有運氣:

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); 
+0

標準addons.mozilla.org拒絕ca nned迴應:*您的加載項使用戶無法永久刪除其我們無法允許的工具欄按鈕。在第一次運行時插入工具欄按鈕是很好的建議,但在每次啓動時這樣做或使其無法移動或刪除它不是。* – nmaier

+0

您是否設法使其工作? –

回答

2

您可以最certanly添加一個圖標到NAV吧。下面的代碼我使用:

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");

記住,你必須有 「YOURBUTTONID」 裏面你BrowserToolbarPalette

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

    </toolbarbutton> 
</toolbarpalette> 

參考:Toolbar - Code snippets