Skip to content Skip to sidebar Skip to footer

CustomEvent() To An XUL Tab - Firefox Addon

For many reasons, I have to open up XUL in a tab, instead of using a standard window. I wish to send custom events to this tab, and here's how my code looks like : myextension.js

Solution 1:

var event = new pTab.linkedBrowser._contentWindow.CustomEvent("prefwindow-event");

edit:

Proof of concept, open scratchpad, switch environment to browser, run the 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);

Post a Comment for "CustomEvent() To An XUL Tab - Firefox Addon"