<!DOCTYPE html>
<html>
<head>
<title>a.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
姓名:<input type="text" id="name" name="name" />
<a href="javascript:void(0)" οnclick="method1('b.html','address',300,400)">輸入姓名</a><br/>
地址:<input type="text" id="address" name="address" />
<a href="javascript:void(0)" οnclick="method2('b.html','address',300,400)">選擇地址</a><br/>
<input type="submit" value="提交" />
</div>
<script type="text/javascript">
function method1() {
document.getElementById("name").value = window.showModalDialog("b.html", "test",
"dialogWidth:350px;dialogHeight:350px;help:no;status:no");
}
function method2(url,name,w,h)
{
window.open(url,name,"top=100,left=400,width=" + w + ",height=" + h +
",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>b.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><base target="_self">
</head>
<body>
姓名:<input type="text" id="name" name="name"/><br/>
<input type="button" value="提交" οnclick="test1()"/><br/><br/>
地址:<input type="text" id="address" name="address"/><br/>
<input type="button" value="提交" οnclick="test2()"/>
<script type="text/javascript">
function test1(tag){
window.returnValue = document.getElementById("name").value;
window.close();
}
function test2(){
window.opener.document.all.address.value = document.getElementById("address").value;
window.close();
}
</script>
</body>
</html>