Categories
JavaScript Answers

How to call JavaScript function in an iframe?

Spread the love

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.

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 *