Categories
JavaScript Answers

How to change iframe src with JavaScript?

Spread the love

Sometimes, we want to change iframe src with JavaScript.

In this article, we’ll look at how to change iframe src with JavaScript.

How to change iframe src with JavaScript?

To change iframe src with JavaScript, we set the src property of the iframe element.

For instance, we write

document.getElementById("calendar").src = loc;

to select the iframe with ID calendar with getElementById.

Then we set the src attribute of the iframe by setting the src property of the iframe to the loc URL string.

Conclusion

To change iframe src with JavaScript, we set the src property of the iframe element.

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 *