References for Multiple Windows
This example demonstrates how subwindows can communicate with objects, functions and variables in the window or frame that creates the subwindow.
Every window object has a property called opener, this property contains a reference to the window or frame that held the script whose window.open( ) statement generated the subwindow, for the main window or frame this value is null.
Code:
Main Window
<html>
<head>
<title>Main Window</title>
<script type="text/javascript">
function newWindow()
{
window.open("subwindow.html", "subwindow", "width=300,height=300");
}
</script>
</head>
<body>
<form>
<input type="button" value="New Window" onclick="newWindow()" />
<br />
Text from subwindow:
<input type="text" name="txt" />
</form>
</body>
</html>
Subwindow
<html> <head> <title>Subwindow</title> </head> <body> <form onsubmit="return false"> <input type="text" name="txt2" /> <input type="submit" onclick="opener.document.forms[0].txt.value = document.forms[0].txt2.value" /> </form> </body> </html>
Note: the parent-child terminology doesn’t apply to subwindows.
Leave a Reply
You must be logged in to post a comment.
