I am trying to write a Firefox extension that adds elements to a loaded page. So far I get the root element of the document through
var domBody = content.document.getElementsByTagName("BODY").item(0);
and create new elements with
var newDiv = content.document.createElement("div");
and actually it worked pretty well. But problems arose when I added a button with the onclick attribute. As long as the button displays correctly, I get an error message. I already asked here , and the answer with document.createElement () (without content) works.
But if I remove the "content". everywhere, the real problem begins. Firstly, domBody is null / undefined, regardless of how I try to access it, for example. document.body (And actually I add all the elements _after_ the document is fully loaded. At least I think so). And secondly, all other elements look different. It seems that style information like element.style.width = "300px" is no longer being considered.
In short, with "content.document" everything looks good, but the button.onclick button causes an error. only with the "document" button works, but the elements are no longer displayed correctly. Does anyone see a solution for this.
source share