6

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?

Paras Chopra
  • 4,029
  • 4
  • 21
  • 19
  • A similar issue has been discussed here but the workaround doesn't work for me http://www.telerik.com/community/forums/aspnet-ajax/editor/document-domain-access-denied-in-ie-6.aspx – Paras Chopra Mar 21 '10 at 11:57
  • 1
    Sorry but, what is that CodeMirror_boilerplate object in the other [answer][1]? A div? An iframe? What? [1]:http://stackoverflow.com/questions/2486901/how-to-set-document-domain-for-a-dynamically-generated-iframe/2487023#2487023 – JwJosefy Oct 06 '11 at 23:05

1 Answers1

9

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

var u = 'javascript:(function(){document.open();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.

Paras Chopra
  • 4,029
  • 4
  • 21
  • 19