Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript访问Iframe#文档_Javascript_Html_Iframe - Fatal编程技术网

如何使用javascript访问Iframe#文档

如何使用javascript访问Iframe#文档,javascript,html,iframe,Javascript,Html,Iframe,我有一个无法访问的框架,从对框架的初始检查中,我注意到框架包含一个#文档,然后我编写了一个代码来访问该框架 $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]

我有一个无法访问的框架,从对框架的初始检查中,我注意到框架包含一个#文档,然后我编写了一个代码来访问该框架

$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;        
最后一行返回restricted,并且
iframe.contentDocument
返回
null

然后我尝试访问框架文档,它是一个带有
iframe.children[0]
的#文档,它返回
未定义的
,然后我让数组保持打开状态,但什么也没有发生。我在帧上运行的所有代码返回未定义的如何访问此帧#document?

iframe.contentWindow.document
,但仅当原点相同时,因为。

如果原点不相同,我如何设置原点?不幸或幸运的是,我们无法设置原点。如果您需要访问其他来源的文档,有两种方法,仅当服务器具有访问控制允许来源时才执行ajax GET/POST请求:yourDomine(或*)或从服务器端执行GET/POST我知道如何配置XHR,但我不知道如何访问控制允许来源头…这是服务器端头,如果您不控制服务器或此标头不存在,则唯一的方法是从服务器端执行GET/POST,而不是从浏览器。如果您控制服务器,这取决于服务器代码,但这非常简单;