简体   繁体   中英

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

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

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/

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