如何使用JavaScript访问iframe #document

时间:2018-06-23 20:52:58

标签: javascript html iframe

我有这个框架我无法访问,从对框架的初始检查起,我注意到该框架包含#document,然后我编写了代码以访问该框架。

$body = document.body;    
$body.children[3];    
$yo = $body.children[3];
$yo.children[0];    
$next = $yo.children[0];    
$next.children[3];    
$plus = $next.children[3];    
$plus.children[0];    
$star = $plus.children[0];    
$star.children[0];    
$staragain = $star.children[0];    
$staragain.children[1];    
$nextstar = $staragain.children[1];    
$nextstar.children[1];    
$afternext = $nextstar.children[1];    
$afternext.contentWindow;        

最后一行返回受限,并且
iframe.contentDocument返回null。 然后,我尝试访问框架文档,该框架文档是带有iframe.children[0]的#文档,它返回了undefined,然后我将数组保持打开状态,但是什么也没有发生。我在框架上运行的所有代码都返回undefined,该如何访问这个框架#document?yoyoyo

1 个答案:

答案 0 :(得分:0)

iframe.contentWindow.document,但仅由于Same-origin policy而导致原点相同时。

相关问题