Balakumar
Balakumar

Reputation: 131

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

In my parent window I have one iframe. I want to get the anchor tags present inside the iframe from the parent window. If it is possible please give the suggestion, otherwise please tell why it is not possible.

Upvotes: 0

Views: 1199

Answers (1)

YardenST
YardenST

Reputation: 5256

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)

Upvotes: 1

Related Questions