Forum Moderators: open
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Window A</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
<!--
//Global variable to hold window object reference
var myWindow
//This function opens the window
function openWindow(){
myWindow=window.open('js_opened.htm')
}
//This function sets the value of a textbox in the opened window
function setTextbox(){
myWindow.document.forms[0].txtTest.value='Hello from opener!'
}
//-->
</script>
<style type="text/css">
</style>
</head>
<body>
<h1>Accessing Opened/Opener Windows</h1>
<p>This is an example of scripting between a window and a child window spawned by a window.open() command.
Please note that because of security settings, the two pages must be in the same web domain for this function
to work as expected.</p>
<form method="post" action="">
<input type="button" onclick="openWindow()" value="Open Window" />
<input type="button" onclick="setTextbox()" value="Set textbox in opened window" />
<input type="text" name="txtTest2" id="txtTest2" value="" />
</form>
</body>
</html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Window B</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
<!--
function setOpenerText(){
window.opener.document.forms[0].txtTest2.value='Hello from opened!'
}
//-->
</script>
<style type="text/css">
</style>
</head>
<body>
<h1>Opened Window</h1>
<p>This is the opened child window. Click the button to set the value of a textbox in the opener window.</p>
<form method="post" action="">
<input type="button" onclick="setOpenerText()" value="Set Textbox on Opener" /><br /><br />
<span>To be set by opener </span><input type="text" id="txtTest" name="txtTest" value="" />
</form>
</body>
</html>