Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change source location of iframes in JavaScript?

How do you change source location of iframes in JavaScript?

For example, but the click of a button or a link, change this:

<iframe src=""></iframe>

...into this:

<iframe src="http://stackoverflow.com/"></iframe>

And, if you want to do one better, how do I change multiple iframes within the same page (using name or some other identifier)?

like image 888
Xonatron Avatar asked Sep 16 '25 00:09

Xonatron


1 Answers

First, assign you iframe an id. This would look like

<iframe id="youridname" src=""></iframe>;. 

Then your JavaScript command would be

document.getElementById("youridname").src = "http://stackoverflow.com";
like image 83
Neil Flodin Avatar answered Sep 18 '25 18:09

Neil Flodin