Firefox add-on: Injected HTML

505 Views Asked by At

I'm trying to write an add-on for firefox and i'm having a problem- When the user right-clicking on the page the add-on is adding an element to the page's body using

document.body.appendChild(myElement);

myElement has a button and i want that "onClick" it will call a xmlHttpRequest and handle the response in some why. I've tried to inject the two scripts using

document.getElementsByTagName('head')[0].appendChild(xmlRequestFunction);
document.getElementsByTagName('head')[0].appendChild(handleResponseFunction);

but it didn't work because of (i assume) a security problem. What can i do?

Thanks

1

There are 1 best solutions below

2
Wladimir Palant On BEST ANSWER

Do not use onclick when working with content, use addEventListener instead (see https://developer.mozilla.org/en/XPCNativeWrapper#Limitations_of_XPCNativeWrapper if you need to know why). Like this:

myElement.addEventListener("click", function(event)
{
  var request = new XMLHttpRequest();
  ...
}, false);