loading
Please wait while loading...
Back Call parent window from iframe

Today learn a new function  --- window.parent.

Although iframe is less useful nowadays, we still on some situation, such as ajax upload. Using window.parent, you can call a function on the main frame from the iframe, this to make interaction of the parent window and the iframe window. You can try and find the use in the following example:

 

Parent Window (index.html)

<script>
function hello() {
	alert(123);
}
function add() {
	document.getElementById('div').innerHTML = '<iframe src="i.html" width="200" height="200">';
}
setTimeout("add()",2000);
</script>
<div id="div"></div>

iframe window (i.html)

<script>
function callparent() {
	window.parent.hello();
}
setTimeout("callparent()",3000);
</script>
<body bgcolor="#FF9999">
</body>
Comments
comments powered by Disqus