I'm trying to access the inside of a dynamically inserted iframe (inserted from a script that was loaded from a different domain than the host page) in ie9 on twitter.com so that i can write content into it. I tried setting the src
to both ''
and about:blank
. Accessing the contentDocument
throws an Access denied
error, and accessing the contentWindow
returns nothing. Why is this and is there a way around it? It works in other browsers, but for some reason is seems that Twitter might be doing something to prevent this and I'm curious as to what it is.
Asked
Active
Viewed 1,132 times
2

user730569
- 3,940
- 9
- 42
- 68
-
Can you give some more specific code for what you are trying to do? – Sean Hogan Sep 16 '12 at 22:16
-
Likely dupe of http://stackoverflow.com/questions/14715427/cant-access-an-aboutblank-iframe-in-ie-after-the-document-domain-changes, fixed in IE11. – EricLaw May 13 '14 at 13:59
1 Answers
0
I use the following and I believe it works on all browsers that support iframe
.
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
var iframeDoc = iframe.contentWindow.document;
iframeDoc.open();
iframeDoc.write(html);
iframeDoc.close();
I don't set @src
at all.

Sean Hogan
- 2,902
- 24
- 22