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

I am implementing 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: = frame.contentWindow;
var doc =; <-- ERROR;

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?


Got it to work, finally. A hack inspired by TinyMCE code.

var u = 'javascript:(function(){;document.domain="' + document.domain + '";var ed = window.parent.CodeMirror_boilerplate;document.write(ed);document.close();})()';

frame.src = u;

It sets the document.domain in SRC and not by DOM.

Need Your Help

How to calculate the slope of a point on a terrain data (e.g. Digital Elevation Matrix)

terrain racing linear-interpolation

I want to implement a 3D car racing game and I need to approximate the magnitude and the direction of the slope of any arbitrary point on a terrain.