如何通过工具栏按钮 XUL 打开 Firefox AddOn 的首选项窗格?
我的 FireFox AddOn 的首选项窗格是 XUL 文档(XML 用户界面语言)。该文件名为 options.xul。
在 browser.xul 中,我创建了一个带有选项按钮的工具栏。单击“选项”按钮时,应该会显示由 options.xul 定义的首选项窗格。但我不知道如何从 oncommand 调用首选项窗格。
调用 Javascript 函数非常简单。但是如何调用插件的首选项窗格呢?下面是一个调用 JavaScript 函数的命令,但是如何调用 Preferene 窗格呢?
如果有人可以请在 browser.xul 中发布对以下内容的更改:
<menupopup>
<menuitem label="Options" tooltiptext="Options" oncommand="example.LoadURL('http://www.google.com/')" />
</menupopup>
The Preference Pane for my FireFox AddOn is an XUL document (XML User Interface Language). The file is called options.xul.
In browser.xul, I have created a toolbar with a button for Options. When the Options button is clicked, it should bring up the Preference Pane defined by the options.xul. But I do not know how to call the Preference Pane from oncommand.
Calling a Javascript function is straight forward. But how does one call the AddOn's Preference Pane? Below is an oncommand calling a javascript function but how does one call the Preferene Pane?
If someone could please post the alteration to the following in browser.xul:
<menupopup>
<menuitem label="Options" tooltiptext="Options" oncommand="example.LoadURL('http://www.google.com/')" />
</menupopup>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法打开这样的窗格。首选项窗格是首选项窗口的一部分。您的 option.xul 应该至少看起来像这样
在 browser.xul 中,您的 oncommand 可以使用以下命令打开首选项窗口:
(或者您想要执行 openDialog 的 javascript 中的任何方法)
其他信息 上找到
有关 prefwindows 和窗格的信息可以在https://developer.mozilla.org/en/XUL/prefwindow 或
https://developer.mozilla.org/en/XUL/prefpane
You can not open a pane as such. A preference pane is a part of a preference window. Your option.xul should look at least something like this
In the browser.xul your oncommand could open the preference window using :
(or whatever method in your javascript that you would like to do the openDialog)
Additional information about prefwindows and panes can be found on
https://developer.mozilla.org/en/XUL/prefwindow or
https://developer.mozilla.org/en/XUL/prefpane
我认为“首选项窗格”实际上是指附加组件的选项对话框窗口,而不仅仅是
中的单个
。我还假设您有一个options.xul
,它功能齐全,可以使用附加选项卡中的普通选项按钮用作选项对话框。我发现打开选项对话框需要与上面显示的 tazyDevel 有所不同的选项,这样它看起来就像是从附加组件选项卡打开的一样。我不确定这是否是 2012 年到 2014 年(当我编写下面的代码时)的差异,或者是否只是实现差异。如果我没记错的话,当我写这篇文章时,我检查了 Firefox 如何启动选项对话框窗口并复制那里正在使用的选项。
我使用以下代码从附加组件主对话框窗口中的按钮打开我的附加组件之一的选项对话框(除了通过附加组件选项卡可用之外):
XUL(打开附加组件的按钮)选项对话框):
JavaScript:
根据代码的组织方式,您可能需要手动应用一些首选项和/或使用首选项观察器将更改传播到需要了解它们的内容。
myExtension
是您用来调用扩展程序的任何内容的占位符。假定包含函数的单个对象变量,就像您用来标识chrome.manifest
文件中的内容的myExtension
一样。I assume that by "Preference Pane" you actually mean the Option Dialog window for your add-on, not just a single
<prefpane>
within the<prefwindow>
. I also assume that you have anoptions.xul
which is fully functional for use as a options dialog using the normal option button from the add-on tab.I found that somewhat different options than tazyDevel shows above were needed to have the options dialog open so that it appears as if it was opened from the add-ons tab. I am not sure if this is a difference from 2012 to 2014 (when I wrote the code below), or if it is just an implementation difference. If I recall correctly, when I wrote this, I checked to see how Firefox was launching the options dialog windows and copied the options that were being used there.
I use the following code to open the options dialog for one of my add-ons from a button in the add-on's main dialog window (in addition to having it available through the add-ons tab):
XUL (the button that opens the options dialog):
JavaScript:
Depending on how your code is organized, you may need to manually apply some preferences and/or have preference observer(s) which propagate the changes to what needs to know about them.
myExtension
is a placeholder for whatever you are using to call your extension. A single object variable containing functions is assumed, as ismyExtension
being what you use to identify your content in yourchrome.manifest
file.