【发布时间】:2015-12-28 03:50:52
【问题描述】:
随着多进程 Firefox 的到来,我决定使用 Addon-SDK 重写我的插件。
我的插件主要是一个带有大量菜单的工具栏。
addonsdk 不提供任何方式来构建菜单。 So I found this method 通过它我可以将它们添加到现有的工具栏。但是,我找不到任何方法来创建这样的菜单并将它们添加到 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,它也不会添加到窗口中。
【问题讨论】:
-
关于异步问题,为什么不能推迟执行,直到加载完成?
-
我可以这样做吗? (你问我为什么不能推迟执行 - 我不能因为我不知道我可以:))
-
通常异步函数具有回调,允许您在加载完成时执行函数。我不熟悉 Firefox SDK,但我相信这是可能的。
-
感谢您的想法,朋友。我必须把一些东西放在一起并与学习曲线作斗争......
-
这个link 和这个other link 可能会帮助你...
标签: javascript firefox-addon-sdk xul