Sometimes, we want to call JavaScript function in an iframe.
In this article, we’ll look at how to call JavaScript function in an iframe.
How to call JavaScript function in an iframe?
To call JavaScript function in an iframe, we get the window object of the iframe with the contentWindow property.
For instance, we write
document.getElementById("resultFrame").contentWindow.Reset();
to select the iframe with getElementById.
Then we call the contentWindow.Reset global function in the iframe.
contentWindow is the window object of the iframe.
Conclusion
To call JavaScript function in an iframe, we get the window object of the iframe with the contentWindow property.