Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
197
rated 0 times [  199] [ 2]  / answers: 1 / hits: 22982  / 14 Years ago, sun, march 21, 2010, 12:00:00

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?


More From » iframe

 Answers
31

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.


[#97280] Wednesday, March 17, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trayvon

Total Points: 35
Total Questions: 117
Total Answers: 88

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;