Sometimes, we want to access elements of parent window from iframe with JavaScript.
In this article, we’ll look at how to access elements of parent window from iframe with JavaScript.
How to access elements of parent window from iframe with JavaScript?
To access elements of parent window from iframe with JavaScript, we can use the window.parent.document
property to get the parent window’s document.
For instance, we write
window.parent.document.getElementById("target");
to use the window.parent.document
property to get the parent window’s document.
Then we call getElementById
to select the element in the parent window by its ID.
Conclusion
To access elements of parent window from iframe with JavaScript, we can use the window.parent.document
property to get the parent window’s document.