开发者

Firefox add-on: Injected HTML

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.appen开发者_开发技巧dChild(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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜