关于 html:如何使用 javascript 访问 iframe #document | 珊瑚贝

How do i access Iframe #document with javascript


我有这个框架我无法访问,从最初检查框架我注意到框架包含#document 然后我写了一个代码来访问框架。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$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,它返回了undefined,然后我让数组保持打开状态但没有发生任何事情。我在框架上运行的所有代码都返回未定义我如何访问这个框架#document ?yoyoyo.


iframe.contentWindow.document 但前提是原点相同,因为同源策略。

  • 如果原点不同,我如何设置原点?
  • 不幸或幸运的是,我们无法设置原点。如果您需要访问其他来源的文档,有两种方法,只有在服务器具有 Access-Control-Allow-Origin 时才执行 ajax GET/POST 请求:yourDomine (或 *) developer.mozilla.org/es/docs/ Web/HTTP/Headers/… 或从服务器端执行 GET/POST
  • 我知道如何配置 XHR,但我不知道如何访问 Access-Control-Allow-Origin 标头…
  • 它是服务器端标头,如果您不控制服务器或此标头不存在,唯一的方法是从服务器端执行 GET/POST,而不是浏览器。如果您控制服务器,则取决于服务器代码,但这真的很容易。
  • php 中的示例: header(‘Access-Control-Allow-Origin: *’);
  • 我怎么知道这个标题是否存在?
  • 使用浏览器进入页面(如果可能)打开控制台(通常是 F12)搜索网络并重新加载页面。查找资源,例如 index.html 并查找响应标头。示例:此站点 enable-cors.org/server_php.html 具有 Access-Control-Allow-Origin: * header
  • 它不存在。
  • 我可以要求吗?
  • 唯一的方法是从服务器端 GET/POST
  • 我运行 iis,我如何从服务器端执行此操作?
  • 。网 ? stackoverflow.com/questions/27108264/…
  • 你知道我如何在 iis 上运行这些代码吗?


来源:https://www.codenong.com/51004952/

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?