javascript - CustomEvent() to an XUL tab - Firefox addon -
for many reasons, have open xul in tab, instead of using standard window. wish send custom events tab, , here's how code looks :
myextension.js :
.. var ptab = window.gbrowser.loadonetab("chrome://myextension/path/options.xul", {inbackground: false}); var pwin = window; var event = new pwin.customevent("prefwindow-event"); pwin.dispatchevent(event); ..
options.xul code:
window.addeventlistener("load", init, false); window.addeventlistener("prefwindow-event", myevent, false, true); .. myevent: function(e) { dump("my event : " + e.details ); }, ..
however, don't event. have tried possible options. enabled/disabled usecapture
, wantsuntrusted
of addeventlistener(). after realizing there restrictions in sending custom events between windows, tried dispatching event tab element, :
ptab.dispatchevent(event);
that wouldn't work either. 1) event dispatch work perfectly fine if use dialog window instead of tab (opendialog
instead of loadonetab
). 2) tab element only inherits dispatchevent
, not customevent
so question is, there way send custom events , have received in tab?
var event = new ptab.linkedbrowser._contentwindow.customevent("prefwindow-event");
edit:
proof of concept, open scratchpad, switch environment browser, run following snippet
var url = 'data:text/html;charset=utf-8,'; var content = '<html><script>addeventlistener("hello",function(){alert("hello")},false)</script></html>' var tab = gbrowser.loadonetab(url+encodeuricomponent(content), {inbackground: false}); tab.addeventlistener("load", function(){ var evt = new tab.linkedbrowser.contentwindow.customevent("hello"); tab.linkedbrowser.contentwindow.dispatchevent(evt); }, false);
Comments
Post a Comment