How to set the scr in an iframe with javascript

Categories:  Web
Labels:  html, javascript

How to dynamically set the scr in an iframe javascript, with the following code you can make changes to the scr in an iframe using javascript, very usefull in html web desing.

Html

<input type="button" name="calendarSelection" title="change" value="Change site" onClick="newSite()" />
<iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe>

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)];
}

Here’s the jQuery way to do it:

$('#calendar').attr('src', loc);

Source

Related Posts:

Social Profiles

Alvistec spanish
Plan Alvistec in Youtube
Privacy policy

This web site uses third's cookies and the Google's cookies to offer services, personalize ads and analyze traffic (Google analytics).
The information on the use of the this web site is shared with Google and another ads provider platforms. When you using this web site, you accept cookies use.
See more about the Cookies

This web accept cryptocoin donations
BTC address, LTC, ETH, Uphold:
Why donations?