Firefox Addon SDK:向用户显示选项的方式?
我对使用 Firefox 进行插件开发还很陌生。我选择了 addon sdk 将我的 chrome 扩展移植到 Firefox。
您建议如何向用户显示选项页面/选项面板/选项窗口?
从我的插件目录加载 options.html 文件工作得很好(addTab(data.url(“options.html”));),但据我所知,我无法将页面修改附加到它。因此我无法与 main.js 通信来保存我的选项,对吗?
另外用户应该如何访问它? 在 Chrome 中这很容易。右键单击您的图标 ->选项将为您打开。 有没有办法为 Firefox 创建类似的行为?
对此有何建议?
I'm quite new to addon development with firefox. I picked the addon sdk for porting my chrome extension to firefox.
What would you suggest to display a options page / options panel / options window to a user?
Loading a options.html file from my addon directory works quite fine (addTab(data.url("options.html"));), but i can't attach page-mods to it, as far as a i know. Therefore i can't communicate with the main.js to save my options, right?
Also how should the user access it?
In chrome this is quite easy. Rightclick your icon -> options and it opens up for you.
Are there ways to create a simliar behaviour for firefox?
Any suggestions on that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从附加 SDK 1.4 开始,您将拥有
simple- prefs
模块。它将自动为您的附加组件生成内联选项 - 这些选项直接显示在附加组件管理器中的扩展页面上。这应该是显示选项的首选方式。缺点:以编程方式打开选项并不简单,即使对于经典的附加组件也是如此。而且 SDK 似乎不支持复杂的控件(内联选项的可能性的文档),仅支持最基本的。如果您想自己推出,您可能需要将“选项”按钮集成到 下拉面板。您还应该能够通过
向其附加内容脚本page-mod
package,类似这样的东西应该可以工作:这里的缺点:使用标准化的方式来显示附加选项(通过附加组件管理器)是不可能的,SDK不支持支持除内联选项之外的任何内容。
Starting with the Add-on SDK 1.4 you have the
simple-prefs
module. It will automatically generate inline options for your add-on - these are displayed directly on your extension's page in the Add-ons Manager. That should be the preferred way to display options. The downside: opening the options programmatically is non-trivial, even for classic add-ons. And the SDK doesn't seem to support complicated controls (documentation of what's possible with inline options), only the most basic ones.If you want to roll your own, you probably want to integrate an "Options" button into a drop-down panel. You should also be able to attach a content script to it via
page-mod
package, something like this should work:Downside here: using the standardized way to display add-on options (via Add-ons Manager) won't be possible, the SDK doesn't support anything but inline options.
感谢
Wladimir Palant
指出了方向,但我还是花了相当长的时间才弄清楚最终的代码。我把我的结果放在这里,供以后其他人参考。 (出于详细说明的目的,我在这里稍微简化了代码,但主要结构应该是正确的。)content.js:(单击链接打开选项页面)
background.js:
options.js:(此页面也位于内容脚本上下文)
参考:
https://developer.mozilla.org/en-US /Add-ons/SDK/High-Level_APIs/tabs
Thanks
Wladimir Palant
for pointing out the direction, yet it still took me quite a while to figure out the final code. I put my result here for reference of others in the future. (I simplified the code a little bit here for elaboration purpose, but the main structure should be correct.)content.js: (click a link to open the options page)
background.js:
options.js: (this page is also on the content script context)
Reference:
https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
在这种情况下,您需要使用 Port.on()/Port.emit() 从 options.html 发送控制选项,例如单击设置按钮。和“选项卡”模块
In this case you need to use Port.on()/Port.emit() to send a controll option from options.html, like click on setting button. And "tabs" module