change iframe src by javascript
// so you got an iframe (id="myiframe"). In that page you have an element id="theprice" and you want to change its value
// from the parent page do this in your javascript:
var iframevar = document.getElementById('myiframe');
var elmnt = iframevar.contentWindow.document.getElementById("theprice");
elmnt.innerHTML = theNewPrice;
3.83
6
<script type="text/javascript">
function iframeDidLoad() {
alert('Done');
}
function newSite() {
var sites = ['http://getprismatic.com',
'http://gizmodo.com/',
'http://lifehacker.com/']
document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)];
}
</script>
<input type="button" value="Change site" onClick="newSite()" />
<iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe>
Thank you!
6
0
0
0
//change iframe src get the iframe then . and src and provide a value
document.getElementById("myFrame").src = "https://facobook.com";
Thank you!
0
0
4.5
8
Do not use Inquisitive Iguana's answer! Notice the spelling of facebook in https://facobook.com. Visiting the webpage downloads malware onto your system
Message from my antivirus on my mac: "We've blocked the threat URL:Mal on http://dt.gnpe.com/ptmd from being downloaded."
Thank you!
8
0
Are there any code examples left?
New code examples in category Javascript