1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>parent.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function openWin() {
var style = "width=300,height=400,location=no,directories=no,toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no";
window.open("2.html","newwindow",style);
}
function setValue(name,hname) {
document.getElementById("name").value = name;
document.getElementById("hname").value = hname;
}
</script>
</head>
<body>
name:<input type="text" id="name"/><a href="#" οnclick="openWin()">xuanze</a>
<input type="hidden" name="name" id="hname"/>
</body>
</html>
2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>child.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function selectedThis(obj) {
var name = obj.value;
var hname = obj.id;
window.opener.setValue(name,hname);//调用父窗口的方法进行传值
window.opener = null; //我认为是给了window.opener赋一个值,让它变成了一个OBJECT.因为,opener存在的时候用 //JS关闭它是不需要确认的。所以,这行语句一般 用于window.close();前。
window.open('','_self');
window.close();
}
</script>
</head>
<body>
nameSelect:<br/>
<input type="radio" name="name" id="name1" value="name1" οnclick="selectedThis(this)"/>name1
<input type="radio" name="name" id="name2" value="name2" οnclick="selectedThis(this)"/>name2
<input type="radio" name="name" id="name3" value="name3" οnclick="selectedThis(this)"/>name3
</body>
</html>
11
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<script language="javascript">
<!--
function openChild(){
var k = window.showModalDialog("22.html","window","dialogWidth:335px;status:no;dialogHeight:300px");
if(k != null)
document.getElementById("txt11").value = k;
}
//-->
</script>
</HEAD>
<BODY>
<br>传递到父窗口的值:<input id="txt9" type="text" value="3333333333333"><br>
返回的值:<input id="txt11" type="text"><br>
子窗口设置的值:<input id="txt10" type="text"><br>
<input type ="button" value="openChild" οnclick="openChild()">
</BODY>
</HTML>
22
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
</HEAD>
<BODY>
<br>父窗口传递来的值:<input id="txt0" type="text"><br>
输入要设置父窗口的值:<input id="txt1" type="text"><input type ="button" value="设置父窗口的值" οnclick="setFather()"><br>
输入返回的值:<input id="txt2" type="text"><input type ="button" value="关闭切返回值" οnclick="retrunValue()">
<input type ="button" value="关闭刷新父窗口" οnclick="">
</BODY>
</HTML>
<script language=javascript>
<!--
var k=window.dialogArguments;
//获得父窗口传递来的值
if(k!=null)
{
document.getElementById("txt0").value = k.document.getElementById("txt9").value;
}
//设置父窗口的值
function setFather()
{
k.document.getElementById("txt10").value = document.getElementById("txt1").value
}
//设置返回到父窗口的值
function retrunValue()
{
var s = document.getElementById("txt2").value;
window.returnValue=s;
window.close();
}
//-->
</script>