javascript 锚点面板 +小部件、firefox 插件
我是一个开发 Firefox 插件的菜鸟。我已经能够成功地将面板(直到它损坏)锚定到我的小部件上。锚面板充当某种菜单。我陷入困境的是:我希望能够调用另一个面板来显示我的锚面板的“菜单”项之一。我该怎么做呢?菜单面板和列表面板的脚本当前位于 main.js 中。
这是菜单面板的代码:
var menuList = panels.Panel({
width: 102,
height: 90,
contentURL: data.url('list/menu-list.html'),
});
这是列表面板的代码:
var historyList = panels.Panel({
width: 600,
height: 300,
contentURL: data.url('list/history-list.html'),
contentScriptFile: [data.url('jquery-1.7.1.js'),
data.url('list/history-list.js')],
contentScriptWhen: 'ready',
onShow: function() {
this.postMessage(simpleStorage.storage.famhistory);
},
onMessage: function(message) {
require('tabs').open(message);
}
});
在我的菜单 panel.html 中,我有一个链接:
<a href="javascript:showpanel('famlist')">show family list</a>
标题中的脚本:
function showpanel(option) {
this.historyList.show();
};
任何帮助将不胜感激! 谢谢!
I'm a noob developing a firefox add-on. I have been able to successfully anchor a panel(until it breaks) to my widget. The anchor panel acts as a menu of sorts. Where I'm stuck is this: I want to be able to call another panel to show from one of the "menu" items from my anchor panel. How do I go about doing this? The scripts for both menu panel and the list panel currently reside in main.js.
Here is the code for menu panel:
var menuList = panels.Panel({
width: 102,
height: 90,
contentURL: data.url('list/menu-list.html'),
});
And here is the code for the list panel:
var historyList = panels.Panel({
width: 600,
height: 300,
contentURL: data.url('list/history-list.html'),
contentScriptFile: [data.url('jquery-1.7.1.js'),
data.url('list/history-list.js')],
contentScriptWhen: 'ready',
onShow: function() {
this.postMessage(simpleStorage.storage.famhistory);
},
onMessage: function(message) {
require('tabs').open(message);
}
});
In my menu panel.html i have a link:
<a href="javascript:showpanel('famlist')">show family list</a>
and the script in the header:
function showpanel(option) {
this.historyList.show();
};
Any help would be highly appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
面板中的 JavaScript 代码没有执行任何操作的权限 - 它无法打开新面板,也无法与扩展程序通信。您需要将一个内容脚本注入到此面板中,该脚本将与扩展程序进行通信,如下所示:
内容脚本
menu-list.js
需要监听链接点击并向必要时进行扩展,如下所示:The JavaScript code in the panel doesn't have permissions to do anything - it cannot open a new panel and it cannot communicate to the extension. You need to inject a content script into this panel that will communicate back to the extension, something like this:
The content script
menu-list.js
would need to listen to link clicks and send a message to the extension when necessary, something like this: