[英]How to get the anchor tags in the iframe from parent window?
在我的父窗口中有一个iframe,我想从父窗口获取iframe中存在的定位标记。如果可能,请给出建议,否则请说明为什么不可能。
Lets say your iframe is: 假设您的iframe为:
<iframe id="myframe"></iframe>
First you need to access its document 首先,您需要访问其文档
var iframe_doc = document.getElementById("myframe").contentDocument;
Now you can work with it. 现在您可以使用它了。
To get all anchors: 获取所有锚点:
var all_anchors = iframe_doc.getElementsByTagName("a");
(You will not be able to do that if the parent and the iframe don't share the same protocol, domain and port due to same origin policy) (如果由于相同的原始政策,父级和iframe共享的协议,域和端口不同,则您将无法执行此操作)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.