Javascript Child Window invoking a parent window
Here’s on the most simplest example of demonstrating Child window to parent window communication using javascript.
The trick is in using the javascript function “parent.opener.<js method name to invoke in parent>”
Parent window HTML code
<html>
<body>
<script>
function clickme() {
winopen(’DeleteUserConfirmation.html’,'popup575×505′,
‘WIDTH=575,HEIGHT=500,RESIZABLE=No,SCROLLBARS=YES,
TOOLBAR=NO,LEFT=200,TOP=100′);
}
function winopen(url,stuff,morestuff)
{
var popwin = window.open(url,stuff,morestuff);
if( typeof(popwin) != “undefined” && popwin ) {
popwin.focus();
}
}
function forward(){
alert(’function in parent window’);
}
</script>
<a href=”javascript:clickme()”> Click for Popup Window</a>
</body>
</html>
Child window HTML code
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html >
<head>
<title>Second Window</title>
</head>
<table cellpadding=”0″ cellspacing=”0″ border=”0″ width=”100%” >
<tr>
<td align=”center”>
<p> </p>
<p><B>What’s your choice?</B></p>
<p><a href=”javascript:parent.opener.forward();window.close();”><b>Call Parent Window</b></a> <a href=”javascript:window.close()”>Close me</a></p>
</td>
</tr>
</table>
</body>
</HTML>
Written by Ravi Nallakukkala on May 18th, 2007 with comments disabled.
Read more articles on Uncategorized.