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.