使用jquery从动态iframe访问父文档

使用jquery从动态iframe访问父文档,jquery,html,iframe,cross-browser,Jquery,Html,Iframe,Cross Browser,这个问题是问题的继续。我使用以下代码将动态附加到文档中 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("s

这个问题是问题的继续。我使用以下代码将动态
附加到文档中

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>Helpflip</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();
这在Firefox、Chrome和Safari上运行良好。IE 9在第
$行(“#u hf_iFrame”,top.document)上抛出
访问被拒绝

跨域问题是否仍然适用


提前感谢。

您是否尝试省略
.src
行(因此iframe上没有
.src
),因为它不是必需的。IE可能认为您正在尝试进行跨域访问。嗨,Libin,我只是好奇您为什么要用JavaScript编写IFRAME的HTML。如果您创建一个静态HTML页面并将该URL提供给IFRAME,那就不会更好了。而且跨域问题可能存在,因为IFRAME的SRC域将与父页面不同。@jfriend00是。。。但是没有成功…@PurusottamKaushik嘿,我试过了,但是IE、FF和chrome由于同一来源政策而抛出了“拒绝访问”,我无法制作动画,甚至无法访问
,但现在我可以在Firefox、chrome和Safari上访问它。你是在自己的硬盘上运行HTML页面吗?在运行本地驱动器而不是真正的web服务器时,可能会出现跨源问题。
$('#_hf_iFrame', top.document).animate({
      'margin-left': '-400px'
   }, 300).animate({
      'margin-left': '-380px'
   }, 150).animate({
      'margin-left': '-393px'
}, 100);