如何通过Javascript创建XUL工具栏? [英] How to Create XUL Toolbar via Javascript?
问题描述
随着多进程Firefox的到来,我决定使用Addon-SDK重新编写我的插件.
With the coming of multi-process Firefox I have decided to re-write my addon using the Addon-SDK.
我的插件主要是带有广泛菜单集的工具栏.
My addon is mainly a toolbar with an extensive set of menus.
addonsdk不提供任何构建菜单的方法. 因此,我找到了此方法,可以将其添加到现有工具栏中.但是,我找不到任何创建这样的菜单并将其添加到Addon-SDK工具栏的方法.所以我以为我会像创建菜单一样创建工具栏.
The addonsdk does not provide any way to build menus. So I found this method by which I can add them to an existing toolbar. However, I cannot find any way to create menus like this and add them to an Addon-SDK toolbar. So I thought I would just create the toolbar the same way I am creating the menus.
所以,我基本上是想通过javascript(我认为)来创建XUL工具栏:
So, I am basically trying to create an XUL toolbar via javascript (I think):
var MyDelegate = {
onTrack: function(window){
//don't add this to other windows, just the browser window
if(window.location != "chrome://browser/content/browser.xul") {
// console.log("=> win location false");
return;
}
var document = window.document; //we need this to attach the XUL elements
var MyBar = window.document.createElement('toolbar');
MyBar.setAttribute('id', 'MyToolbarID');
MyBar.setAttribute('toolbarname', 'MyTitle');
MyBar.setAttribute('class', 'chromeclass-toolbar');
MyBar.setAttribute('mode', 'full');
MyBar.setAttribute('hidden', 'false');
MyBar.setAttribute('insertafter', 'PersonalToolbar');
}
}
let utils = require('sdk/deprecated/window-utils'); // for new style sdk
utils.WindowTracker(spatDelegate);
要使该工具栏真正构建并显示在浏览器中,我该怎么做?
What do I have to do to make this toolbar actually get built and display in the browser?
[更新]
我不使用SDK工具栏的原因是因为该工具栏是异步创建的,并且不及时存在以获取其html id的句柄.即使我使用浏览器工具箱捕获html id,也不会将其添加到窗口中.
The reason I don't use an SDK toolbar is because the toolbar is created async and does not exist in time to get a handle on it's html id. Even if I fish the html id using the browser toolbox, it doesn't get added to the window.
推荐答案
您需要在工具箱中添加MyBar
:
You need to add MyBar
to the toolbox:
window.document.getElementById("navigator-toolbox").appendChild(MyBar);
这篇关于如何通过Javascript创建XUL工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!