框架页
<html>
<head>
<title>框架页</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<frameset rows="20%,*">
<frame src="sample31_top.htm" name="tip">
<frameset cols="30%,*">
<frame src="sample31_left.htm" name="left">
<frame src="sample31_right.htm" name="right">
</frameset>
</frameset>
</html>
其中上面的sample31-right
<html>
<head>
<title>右框架</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
//更新上框架的内容
function changeTop()
{
window.parent.tip.document.write(myForm.myText.value);
}
//更新左框架的内容
function changeLeft()
{
window.parent.frames[1].document.write(myForm.myText.value);
}
-->
</script>
</head>
<body>
<form name="myForm">
请输入内容:<input type="text" name="myText" value="更新内容"><br>
<input type="button" οnclick="changeTop()" value="更新上框架的内容">
<input type="button" οnclick="changeLeft()" value="更新左框架的内容">
</form>
</body>
</html>
对新开窗口的引用
<html>
<head>
<title>操作新开窗口中的数据</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
//定义一个变量,该变量可以存储代表已经打开窗口的Window对象
var myWin = window.open("sample32_open.htm","onWin");
//打开窗口
function openWin()
{
myWin = window.open("sample32_open.htm","onWin");
}
function inputText()
{
//判断新开窗口是否已经关闭
if (myWin.closed)
{
alert("窗口已经关闭");
}
else
{
myWin.myForm.myText.value = "从原窗口输入的文字";
}
}
-->
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="myText"><br>
<input type="button" value="弹出一个窗口" οnclick="openWin()">
<input type="button" value="在弹出窗口的文本框中输入文字" οnclick="inputText()">
</form>
</body>
</html>
sample32_open.htm 页面源代码:
<html>
<head>
<title>操作原窗口中的数据</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
function inputText()
{
window.opener.myForm.myText.value = "从弹出窗口输入的文字";
}
-->
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="myText"><br>
<input type="button" value="在原窗口的文本框中输入文字" οnclick="inputText()">
</form>
</body>
</html>
<html>
<head>
<title>框架页</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<frameset rows="20%,*">
<frame src="sample31_top.htm" name="tip">
<frameset cols="30%,*">
<frame src="sample31_left.htm" name="left">
<frame src="sample31_right.htm" name="right">
</frameset>
</frameset>
</html>
其中上面的sample31-right
<html>
<head>
<title>右框架</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
//更新上框架的内容
function changeTop()
{
window.parent.tip.document.write(myForm.myText.value);
}
//更新左框架的内容
function changeLeft()
{
window.parent.frames[1].document.write(myForm.myText.value);
}
-->
</script>
</head>
<body>
<form name="myForm">
请输入内容:<input type="text" name="myText" value="更新内容"><br>
<input type="button" οnclick="changeTop()" value="更新上框架的内容">
<input type="button" οnclick="changeLeft()" value="更新左框架的内容">
</form>
</body>
</html>
对新开窗口的引用
<html>
<head>
<title>操作新开窗口中的数据</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
//定义一个变量,该变量可以存储代表已经打开窗口的Window对象
var myWin = window.open("sample32_open.htm","onWin");
//打开窗口
function openWin()
{
myWin = window.open("sample32_open.htm","onWin");
}
function inputText()
{
//判断新开窗口是否已经关闭
if (myWin.closed)
{
alert("窗口已经关闭");
}
else
{
myWin.myForm.myText.value = "从原窗口输入的文字";
}
}
-->
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="myText"><br>
<input type="button" value="弹出一个窗口" οnclick="openWin()">
<input type="button" value="在弹出窗口的文本框中输入文字" οnclick="inputText()">
</form>
</body>
</html>
sample32_open.htm 页面源代码:
<html>
<head>
<title>操作原窗口中的数据</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
function inputText()
{
window.opener.myForm.myText.value = "从弹出窗口输入的文字";
}
-->
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="myText"><br>
<input type="button" value="在原窗口的文本框中输入文字" οnclick="inputText()">
</form>
</body>
</html>