How to set document.domain for a dynamically generated IFRAME?

Posted by Paras Chopra on Stack Overflow See other posts from Stack Overflow or by Paras Chopra
Published on 2010-03-21T11:38:25Z Indexed on 2010/03/21 11:41 UTC
Read the original article Hit count: 325

Filed under:
|
|
|

I am implementing CodeMirror (http://marijn.haverbeke.nl/codemirror/) on a page where document.domain needs to be declared (because of other IFRAMES on the page).

CodeMirror generates a dynamic IFRAME to provide syntax highlighted code editing. The problem is that IE throws up 'Access Denied' (other browsers are fine) at the following piece of code mirror code:

this.win = frame.contentWindow;
...
var doc = this.win.document; <-- ERROR
doc.open();
doc.write(html.join(""));
doc.close();

It turns out IE doesn't inherit document.domain from parent IE. I can set document.domain in the IFRAME contents but IE throws up the error before I can even set the contents. Any ideas how to tackle this problem?

© Stack Overflow or respective owner

Related posts about iframe

Related posts about JavaScript