通过在iframe中呈现外部页面来查询以获取外部网站中使用的所有DOM元素(div)。 [英] Query to get the all the DOM elements(div) used in a external website by rendering the external page in the iframe.

查看:331
本文介绍了通过在iframe中呈现外部页面来查询以获取外部网站中使用的所有DOM元素(div)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在IFrame中获取子节点。



我无法访问iframe内部的元素,也是。如果我尝试渲染谷歌iframe中的.com我收到以下错误。

拒绝在框架中显示'https://www.google.co.in/',因为它设置'X-Frame-Options'到'sameorigin'。



以下是向IFrame添加事件的另一个错误

阻止了一个包含原点的帧http:/ / localhost:53242来自访问跨域框架。



我尝试过:



代码:

< iframe id =displaysrc =https://www.w3schools.com/>< / iframe>

脚本:

elements = document.querySelectorAll('iframe> *');

I am not getting the child nodes inside the IFrame.

I am not able to access the elements inside the Iframe and also.If I try to render google.com in Iframe I am getting the following error.
"Refused to display 'https://www.google.co.in/' in a frame because it set 'X-Frame-Options' to 'sameorigin'."

The following is another error for adding an event to IFrame
Blocked a frame with origin "http://localhost:53242" from accessing a cross-origin frame.

What I have tried:

code:
"<iframe id="display" src="https://www.w3schools.com/"></iframe>"
script:
elements = document.querySelectorAll('iframe>*');

推荐答案

你不能访问iframe中的页面DOM,除非它们已经过编程,以便它们为您的站点提供访问权限。这是出于安全原因。此外,当谈到谷歌时,他们已经配置了他们的网站,以至于你根本无法在iframe中使用它。没有办法规避这些安全措施,否则它们将毫无意义,而且也没有道德理由去做这种事情。
You can't access the DOM of pages in an iframe unless they have been programmed such that they give your site access. This is for security reasons. Furthermore when it comes to google they have configured their site such that you can't use it in an iframe at all. There is no way to circumvent these security measures otherwise they would be pointless and furthermore there is no ethical reason to do this kind of thing either.


这篇关于通过在iframe中呈现外部页面来查询以获取外部网站中使用的所有DOM元素(div)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆