1<iframe id="myIFrame" src="thispage.html"
2 width="100%" height="600"
3 frameBorder="2">
4</iframe>
5
6// Get the iframe
7const iFrame = document.getElementById('myIFrame');
8
9// Let's say that you want to access a button with the ID `'myButton'`,
10// you can access via the following code:
11const buttonInIFrame = iFrame.contentWindow.document.getElementById('myButton');
12
13// If you need to call a function in the iframe, you can call it as follows:
14iFrame.contentWindow.yourFunction();
1<script type="text/javascript">
2function iframeDidLoad() {
3 alert('Done');
4}
5
6function newSite() {
7 var sites = ['http://getprismatic.com',
8 'http://gizmodo.com/',
9 'http://lifehacker.com/']
10
11 document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)];
12}
13</script>
14<input type="button" value="Change site" onClick="newSite()" />
15<iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe>
16
1var html_string= "content";
2document.getElementById('output_iframe1').src = "data:text/html;charset=utf-8," + escape(html_string);
3