简体   繁体   English

带有工具栏的Firefox Addon,来自browser.xul的访问对象

[英]Firefox Addon with toolbar, access object from browser.xul

I am developing a Firefox addon which will be primarily a toolbar but will have some dialog/windows for things like preferences. 我正在开发一个Firefox插件,它主要是一个工具栏,但会有一些对话框/窗口,用于喜欢的东西。

In browser.xul I declare my global variable which I will store all variables within: browser.xul我声明了我的全局变量,我将所有变量存储在:

var coolAddon = {};

Then in my toolbar I want to be able to call methods of coolAddon , for example on button clicks. 然后在我的工具栏中,我希望能够调用coolAddon方法,例如按钮点击。

If I open a dialog from browser.xul , in the dialog I can access coolAddon using window.opener.coolAddon , which works well. 如果我从browser.xul打开一个对话框,在对话框中我可以使用window.opener.coolAddon访问coolAddon ,效果很好。 The problem is this does not work on the toolbar - only on windows/dialogs. 问题是这在工具栏上不起作用 - 仅在窗口/对话框上。 What happens in the toolbar is window.opener is null/undefined . 工具栏中发生的是window.openernull/undefined

How can I access coolAddon that is declared in browser.xul , from within the toolbar? 如何访问coolAddon是在宣布browser.xul ,从工具栏中? I don't want to redeclare it because I need to keep it's current property values (I realise my example does not currently have any properties or methods). 我不想重新声明它,因为我需要保持它的当前属性值(我意识到我的示例目前没有任何属性或方法)。

You should be able to access coolAddon directly from your toolbar. 您应该可以直接从工具栏访问coolAddon。 It is in the browser context. 它位于浏览器上下文中。

Window.opener is only needed when you are in a completely different window. 只有在完全不同的窗口中才需要Window.opener。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM