如何在首次安装时在插件栏上添加图标?
我按照此文档 Mozilla 开发者网络:创建工具栏按钮 为我的插件创建一个按钮。它确实有效,但是当我第一次安装插件时,图标没有显示在插件栏上。
如何让图标在用户安装我的插件后立即出现在插件栏上,然后保留他的位置首选项?
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="chrome://.../content/firefox/browser.css"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript" src="chrome://...../content/firefox/browser.js" />
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id=".....-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
label="...." tooltiptext="Facebook Manager"
oncommand="System.......Toolbar.Show(event)" />
</toolbarpalette>
</overlay>
如何将按钮自动添加到插件栏一次?
我发现这段代码以编程方式添加按钮,它显示了我的按钮,但它与其他按钮混淆了。
var myId = "myaddon-button";
var navBar = document.getElementById("addon-bar");
var curSet = navBar.currentSet.split(",");
if (curSet.indexOf(myId) == -1) {
var set = curSet.slice(0, curSet.length).concat(myId).concat(curSet.slice(curSet.length));
navBar.setAttribute("currentset", set.join(","));
navBar.currentSet = set.join(",");
document.persist(navBar.id, "currentset");
try {
BrowserToolboxCustomizeDone(true);
}
catch (e) {}
}
I followed this doc Mozilla Developer Network: Creating toolbar buttons to create a button for my addon. It does work, but when I install the addon the first time the icon doesn't show on the addon bar.
How can I make the icon appear on the addon bar right after the user install my addon and then keep his location preference?
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="chrome://.../content/firefox/browser.css"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript" src="chrome://...../content/firefox/browser.js" />
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id=".....-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
label="...." tooltiptext="Facebook Manager"
oncommand="System.......Toolbar.Show(event)" />
</toolbarpalette>
</overlay>
How can I add the button automatically to addon bar only once?
I found this code to add the button programmatically, it shows my button, but it messes up with the other buttons.
var myId = "myaddon-button";
var navBar = document.getElementById("addon-bar");
var curSet = navBar.currentSet.split(",");
if (curSet.indexOf(myId) == -1) {
var set = curSet.slice(0, curSet.length).concat(myId).concat(curSet.slice(curSet.length));
navBar.setAttribute("currentset", set.join(","));
navBar.currentSet = set.join(",");
document.persist(navBar.id, "currentset");
try {
BrowserToolboxCustomizeDone(true);
}
catch (e) {}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
插件栏工作正常。
你只需要把你的元素放在工具栏中并给它一个 addon-bar 的 id
示例:
你的 js 放在这里
addon-bar is working fine.
you just have to put your elements inside the toolbar and give it an id of addon-bar
example:
your js goes here
添加按钮不是“安装操作”。您只需将该按钮声明为叠加层的一部分,并在应用扩展叠加层时将其添加进去。
无论如何,看起来您正在将按钮添加到工具栏选项板中...因此,当您右键单击顶部工具栏并单击“自定义...”时,它将显示在按钮的大列表中
插件栏位于底部,您可以像这样添加:
It's not an "install action" to add your button. You simply declare the button as part of the overlay and it's added in when your extension overlay is applied.
Anyway, it looks like you're adding the button to the toolbar palette... so it will show up in the big list of buttons when you right click on the top toolbar and click "Customize..."
The addon bar is at the bottom and you can add to it like so:
看来
addon-bar
已损坏,但我可以通过查看 Firebug 的代码将其添加到nav-bar
上。It seems that the
addon-bar
is broken, but I could add it onnav-bar
looking at Firebug's code.