Diptendu
Diptendu

Reputation: 2158

How to get iframe instance from inside an friendly iframe?

I have an iframe and a script that executes inside it as shown below

<iframe name="myframe" src="test.html">
    <script> <!--My script-->
      ..
    </script>
</iframe>

I want to get an instance of the iframe from inside the iframe. One way is to go to the parent page and access the iframe object as shown below

parent.document.getElementByID('myframe')

Is there any better way (any window or document attribute that points to the parent frame when its present) ?

Upvotes: 0

Views: 699

Answers (2)

user2883973
user2883973

Reputation: 36

Try to use "window.frameElement;" This is documented here: http://www.w3schools.com/jsref/prop_win_frameElement.asp

Upvotes: 1

Rotan075
Rotan075

Reputation: 2615

If I understand correctly, you want to grab the iframe object right?

can't you just use a formal jQuery call of the iframe??:

$('iframe')

see this example: https://jsfiddle.net/79bnmcgb/3/

Upvotes: 0

Related Questions