调度CustomEvent()到prefwindow - Firefox插件 [英] Dispatch CustomEvent() to prefwindow - Firefox addon
问题描述
使用firefox插件,我希望发送一个 CustomEvent() 到首选项窗口。
Working with a firefox addon, I wish to send a CustomEvent() to a preference window.
我使用 openDialog(),并保持对打开的窗口的引用。之后,我尝试发送事件,但事件从未收到。
I open the preference window using an openDialog(), and keep a reference to the opened window. After that, I try to dispatch the event, but the event is never received.
var pWin = window.openDialg("chrome://myextension/path/options.xul", "name", features);
var event = new pWin.CustomEvent("prefwindow-event");
pWin.dispatchEvent(event);
在prefwindow范围内,我在XUL附加的脚本中有这个代码:
In the prefwindow scope, I have this code in the XUL attached script :
window.addEventListener("prefwindow-event", this.catchEvent, false);
但是,我从来没有收到过该事件。 CustomEvent()的文档说
However, I never receive that event. The documentation for CustomEvent() says
创建一个CustomEvent对象时,必须从
创建一个与您相同窗口的对象
When creating a CustomEvent object, you must create the object from the same window as you're going to fire against.
这是否意味着我永远不会将主要扩展范围的事件发送到另一个窗口?如果确实有可能,我在这里做错什么?如果没有,是否有替代方案?
So does it mean that, I can never dispatch an event from my main extension scope to that of another window ? If this is indeed possible, what am I doing wrong here ? If not, is there an alternative ?
推荐答案
我猜想以下将会工作
var pWin = window.openDialg("chrome://myextension/path/options.xul", "name", features);
pWin.addEventListener("load", function(){
var event = new pWin.CustomEvent("prefwindow-event");
pWin.dispatchEvent(event);
}, false);
这篇关于调度CustomEvent()到prefwindow - Firefox插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!