如何为动态生成的IFRAME设置document.domain? [英] How to set document.domain for a dynamically generated IFRAME?
问题描述
我正在实施CodeMirror( http://marijn.haverbeke.nl/codemirror/ )在需要声明document.domain的页面上(因为页面上的其他IFRAMES)。
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生成动态IFRAME以提供语法突出显示的代码编辑。问题是IE在以下代码镜像代码中抛出'Access Denied'(其他浏览器没问题):
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();
事实证明,IE不会从父IE继承document.domain。我可以在IFRAME内容中设置document.domain但IE在我甚至可以设置内容之前抛出错误。任何想法如何解决这个问题?
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?
推荐答案
最后让它发挥作用。受TinyMCE代码启发的黑客攻击。
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;
它在SRC中设置document.domain而不是DOM。
It sets the document.domain in SRC and not by DOM.
这篇关于如何为动态生成的IFRAME设置document.domain?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!