javascript 锚点面板 +小部件、firefox 插件

发布于 2025-01-01 23:45:06 字数 1018 浏览 1 评论 0原文

我是一个开发 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2025-01-08 23:45:06

面板中的 JavaScript 代码没有执行任何操作的权限 - 它无法打开新面板,也无法与扩展程序通信。您需要将一个内容脚本注入到此面板中,该脚本将与扩展程序进行通信,如下所示:

var menuList = panels.Panel({
  width: 102,
  height: 90,
  contentURL: data.url('list/menu-list.html'),
  contentScriptFile: [data.url('jquery-1.7.1.js'),
                      data.url('list/menu-list.js')],
  onMessage: function(message) {
    if (message == "famlist")
      historyList.show();
  }
});

内容脚本 menu-list.js 需要监听链接点击并向必要时进行扩展,如下所示:

$(document).ready(function() {
  $("#famlistLink").click(function() {
    self.postMessage("famlist");
  });
});

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:

var menuList = panels.Panel({
  width: 102,
  height: 90,
  contentURL: data.url('list/menu-list.html'),
  contentScriptFile: [data.url('jquery-1.7.1.js'),
                      data.url('list/menu-list.js')],
  onMessage: function(message) {
    if (message == "famlist")
      historyList.show();
  }
});

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:

$(document).ready(function() {
  $("#famlistLink").click(function() {
    self.postMessage("famlist");
  });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文