How to refresh an iframe using JavaScript?

Sometimes, we want to refresh an iframe using JavaScript.

In this article, we’ll look at how to refresh an iframe using JavaScript.

How to refresh an iframe using JavaScript?

To refresh an iframe using JavaScript, we call iframe.contentWindow.location.reload();.

For instance, we write

const iframe = document.getElementById("youriframe");
iframe.contentWindow.location.reload();

to get the iframe with getElementById.

Then we call iframe.contentWindow.location.reload to reload the iframe.

Conclusion

To refresh an iframe using JavaScript, we call iframe.contentWindow.location.reload();.