繁体   English   中英

如何通过Javascript创建XUL工具栏?

[英]How to Create XUL Toolbar via Javascript?

随着多进程Firefox的到来,我决定使用Addon-SDK重新编写我的插件。

我的插件主要是带有广泛菜单集的工具栏。

addonsdk不提供任何构建菜单的方法。 因此,我找到了可以将它们添加到现有工具栏的方法。 但是,我找不到任何方法来创建像这样的菜单并将其添加到Addon-SDK工具栏。 所以我以为我会像创建菜单一样创建工具栏。

所以,我基本上是想通过javascript创建一个XUL工具栏(我认为):

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

要使该工具栏真正构建并显示在浏览器中,我该怎么做?

[更新]

我不使用SDK工具栏的原因是因为该工具栏是异步创建的,并且不及时存在以获取其html id的句柄。 即使我使用浏览器工具箱捕获html id,也不会将其添加到窗口中。

您需要将MyBar添加到工具箱:

window.document.getElementById("navigator-toolbox").appendChild(MyBar);

暂无
暂无

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

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