문제

Working with a Firefox addon, I wish to send a CustomEvent() to a preference window.

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);

In the prefwindow scope, I have this code in the XUL attached script :

window.addEventListener("prefwindow-event", this.catchEvent, false); 

However, I never receive that event. The documentation for CustomEvent() says

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 ?

도움이 되었습니까?

해결책

I guess the following will work

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);

다른 팁

Paa's code should work.

var pWin = window.openDialg("chrome://myextension/path/options.xul", "name", features); 
pWin.addEventListener("prefwindow-event", function(){pWin.alert('prefwindow-event fired')}, false);
pWin.addEventListener("load", function(){
  var event = new pWin.CustomEvent("prefwindow-event"); 
  pWin.dispatchEvent(event);
}, false);

if not then try this:

var pWin = window.openDialg("chrome://myextension/path/options.xul", "name", features); 
pWin.addEventListener("load", function(){
  pWin.addEventListener("prefwindow-event", function(){pWin.alert('prefwindow-event fired')}, false);
  var event = new pWin.CustomEvent("prefwindow-event"); 
  pWin.dispatchEvent(event);
}, false);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top