Categories
JavaScript Answers

How to invoke JavaScript code in an iframe from the parent page?

Spread the love

Sometimes, we want to invoke JavaScript code in an iframe from the parent page.

In this article, we’ll look at how to invoke JavaScript code in an iframe from the parent page.

How to invoke JavaScript code in an iframe from the parent page?

to invoke JavaScript code in an iframe from the parent page, we get the function from the contentWindow property.

For instance, we write

document.getElementById("targetFrame").contentWindow.targetFunction();

to get the iframe with getElementById.

Then we call the targetFunction function in the iframe after getting it from the contentWindow property.

Conclusion

to invoke JavaScript code in an iframe from the parent page, we get the function from the contentWindow property.

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 *