3

在我的 xul 文件中:

<!DOCTYPE overlay >
<overlay id="custombutton-overlay"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<script src="browserOverlay.js"/>

<!-- Firefox -->
<toolbarpalette id="BrowserToolbarPalette">
  <toolbarbutton id="custom-button-1"/>
</toolbarpalette>


<!-- button details -->
<toolbarbutton id="custom-button-1"
  label="Custom"
  tooltiptext="My custom toolbar button"
  oncommand="xyz.showPanel()"
  class="toolbarbutton-1 chromeclass-toolbar-additional custombutton"
/>

<panel id="thepanel">
  <hbox align="start">
    <image src="warning.png"/>
    <vbox>
      <description value="You have 6 new messages."/>
      <hbox>
        <button label="Read Mail"/>
        <button label="New Message"/>
      </hbox>
    </vbox>
  </hbox>
</panel>

</overlay>

当调用具有以下代码的函数“xyz.showPanel()”时:

var xyz = {
    showPanel: function (e)
    {
        var button = document.getElementById('custom-button-1');
        var panel = document.getElementById('thepanel');
        panel.openPopup(button, 'after_start', 0, 0, false, false);

    }
}

它在错误控制台中给了我错误,上面写着:

错误:TypeError:面板为空

我想在 Firefox 中显示类似“下载”工具栏按钮的面板

我是 Firefox 插件的新手,

那么单击工具栏按钮时如何显示面板?

4

1 回答 1

3

在叠加层中,第一层嵌套元素必须引用 DOM 中已经存在的内容(元素内容将被添加到其中),否则这些元素将被忽略。(该规则的一些例外情况,例如<script>。)

您的面板定义基本上说(与您想要说的相反)

  • 查找id 为“thepanel”的现有 panel
  • 如果找到,将 ahbox及其子项添加到面板
  • 如果不是,则忽略子树。

你需要改变你的 XUL 来为你的面板提供一个容器,例如#mainPopupSet,就像你#BrowserToolbarPalette为你的toolbarbutton.

<overlay ...>
...
<popupset id="mainPopupSet">
  <panel id="thepanel">
    ...
  </panel>
</popupset>
</overlay>
于 2013-08-12T14:52:10.560 回答