繁体   English   中英

Firefox XUL:自动加载工具栏按钮

[英]Firefox XUL: Auto loading toolbar button

我是JS和XUL的新手,所以如果这是菜鸟查询,请多多包涵:-)

我正在开发用于Firefox的扩展程序,该扩展程序在单击工具栏按钮(由我创建)时执行自定义操作。 我已经能够使用mozilla示例创建按钮,但是我看到的是,即使扩展安装成功(并且我重新启动firefox以完成更改),也需要将按钮手动添加到工具栏。 此后,可以根据需要使用它,甚至在后续的FF启动时,它也位于工具栏中。

我想知道扩展成功安装后是否有一种方法可以自动加载按钮。 我的XUL脚本如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css"
  href="chrome://custombutton/content/button.css"?>

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

<script type="application/javascript"
  src="chrome://custombutton/content/button.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="CustomButton[1]()"
  class="toolbarbutton-1 chromeclass-toolbar-additional custombutton"
  />

</overlay>

您需要编写一些javascript代码来实现这一点: 默认情况下添加按钮 还要看看将工具栏按钮添加到现有工具栏

使用insertItem函数: https : //developer.mozilla.org/en/XUL/Method/insertItem您可以1.找到容器,例如导航栏。 2.在之前或之后找到要插入的目标项目。 3.插入您的botton。 4.使其持久。

var nbar = document.getElementById("nav-bar");    
var target = document.getElementById("urlbar-container");    
var elem = nbar.firstChild;    
while (elem) {    
if (elem == target) {    
     break;    
}    
elem = elem.nextSibling;    
}    
nbar.insertItem("your-button-id", elem, null, false);    
document.persist("nav-bar", "currentset");    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM