Categories
JavaScript Answers

How to access elements of parent window from iframe with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *