【发布时间】:2012-10-18 15:22:28
【问题描述】:
可能重复:
Permission Denied IE iFrame
Access parent document from dynamic iframe using jquery
我正在尝试使用$('#_hf_iFrame', top.document) 从动态<iframe> 子级访问父文档。它适用于 Firefox、Chrome 和 Safari,但 IE 会抛出 Access Denied 异常。
我正在使用以下代码动态创建<iframe>。
这个问题是这个问题的延续。我使用以下代码将动态附加到文档中。
var _hf_iFrame = document.createElement("iframe");
_hf_iFrame.setAttribute("id", "_hf_iFrame");
_hf_iFrame.setAttribute("name", "_hf_iFrame");
_hf_iFrame.setAttribute("allow-transparency", true);
_hf_iFrame.setAttribute("style", "height: 354px; width: 445px; border: 0; top: 23%; position: fixed; left:0; overflow: show; background:transparent;");
document.body.appendChild(_hf_iFrame);
_hf_iFrame.setAttribute("src", "javascript:false");
var myContent = '<!DOCTYPE html>'
+ '<html><head><title></title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script><script type="text/javascript" src="http://somedomain.com/js/core.js"></script></head>'
+ '<body style="margin: 0px;"></body></html>';
_hf_iFrame.contentWindow.document.open('text/html', 'replace');
_hf_iFrame.contentWindow.document.write(myContent);
_hf_iFrame.contentWindow.document.close();
我该如何解决这个问题?
【问题讨论】:
-
看起来你想问和这里一样的问题:stackoverflow.com/questions/12947122/…。对于给定主题只有一个问题。如果您的其他问题不够清楚(这似乎是个问题),请编辑它。
-
@jfriend00 很抱歉针对同一主题创建多个问题..
-
看起来可以在这里回答:stackoverflow.com/questions/1886547/…
-
@jfriend00 非常感谢...该链接很有帮助。但是请看我的回答