简体   繁体   中英

How to get the anchor tags in the iframe from parent window?

在我的父窗口中有一个iframe,我想从父窗口获取iframe中存在的定位标记。如果可能,请给出建议,否则请说明为什么不可能。

Lets say your iframe is:

<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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM