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.