I have an iframe that opens a new webpage.
In that webpage, I want to access a function on the window of the iframe.
I try to call window.opener.myFunction()
, but the opener is the <iframe>
's parent window, and not the <iframe>
's window.
Because of the dynamic nature of the page, I don't want to explicitly get the contentWindow of the <iframe>
from the parent window. Does anyone know of a workaround?
If you know the <iframe>
's id, you could use getElementById().
For example:
The first webpage would have:
<iframe id="launcher"></iframe>
And the launched page could use:
window.opener.getElementById("launcher").myFunction();
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.