Change iFrame src attribute
xxxxxxxxxx
// Get the iframe by id and set new src attribute
document.querySelector("#viewing-frame").src = "path/to/new/src";
You can also use ".viewing-frame" to get the iframe by class or you can get the iframe directly with "iframe"
xxxxxxxxxx
// 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;
xxxxxxxxxx
<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>
xxxxxxxxxx
$('#iframe').on('load', function() {
alert('frame has (re)loaded ');
});
xxxxxxxxxx
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."