aa.htm
<html>
<head>
<title>父窗口</title>
<script language="javascript" type="text/javascript">
var newWindow;
function openWindow(){
newWindow = window.open("bb.htm", "", "width=400,height=300");
}
function changeChild(){
//取出父窗口文本框傳值給子窗口文本框
newWindow.document.getElementById("ct").value=document.getElementById("ft").value;
//清空父窗口
document.getElementById("ft").value = "";
}
//便利子窗口傳遞過來的對象
function blobj(){
for(ind in newWindow){
alert(newWindow[ind]);
}
}
</script>
</head>
<body>
<input type="button" value="開啟子窗口" οnclick="openWindow()" /><br/>
<input type="text" id="ft"/><input type="button" value="傳值" οnclick="changeChild()"/><br/>
<input type="button" value="便利傳遞過來的對象" οnclick="blobj()"/>
</body>
</html>
bb.htm
<html>
<head>
<title>子窗口</title>
<script language="javascript" type="text/javascript">
//傳值函數(shù)
function chparentval(){
//子窗口獲得文本框的值傳遞給父窗口
opener.document.getElementById("ft").value = document.getElementById("ct").value;
//子窗口值清空
document.getElementById("ct").value = "";
}
//子窗口向父窗口傳遞對象
function fcobj(){
var obj = ["吃飯","睡覺","打豆豆"]
window.returnValue = obj;
opener.document.getElementById("ft").value = "提示:子窗口傳遞過來一個對象";
}
</script>
</head>
<body>
輸入值:<input type="text" id="ct"/>
<input type="button" οnclick="chparentval()" value="從子窗口中往父窗口傳值"/><br/>
<input type="button" value="子窗口向父窗口傳遞對象" οnclick="fcobj()"/>
</body>
</html>
聯(lián)系客服