I'm trying to add some html elements inside a iframe, to personalize a site. I'm building a browser extension, so there is no cross-domain problem. I have the iframe:
<iframe id="container" src="http://www.google.com">
<p>Your browser does not support iframes.</p>
</iframe>
and then, when the document is already loaded, I create the element and insert it... But it is never shown in the iframe. But I am allowed to get an iframe-existent element and to change it's properties. So, I have access to the elements but not for create new ones? Why?
var ifr = document.querySelector("#container");
var ifrDoc = ifr.contentWindow || ifr.contentDocument;
if (ifrDoc.document) ifrDoc = ifrDoc.document;
var elem = ifrDoc.createElement("div");
elem.innerHTML = "Demo Box";
elem.style.width = "50px";
elem.style.height = "50px";
elem.style.position = "absolute";
elem.style.background = "red";
ifrDoc.body.appendChild(elem);
Here a JSFiddle demo to understand the problem (remember extensions have another privileges): http://jsfiddle.net/TH48e/40/
Any idea?