2025-03-25

[html]
<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="開啟子窗口" onclick="openWindow()" /><br/>  

<input type="text" id="ft"/><input type="button" value="傳值" onclick="changeChild()"/><br/>  

  

<input type="button" value="便利傳遞過來的對象" onclick="blobj()"/>  

</body>  

  

</html>  

 

<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="開啟子窗口" onclick="openWindow()" /><br/>

<input type="text" id="ft"/><input type="button" value="傳值" onclick="changeChild()"/><br/>

 

<input type="button" value="便利傳遞過來的對象" onclick="blobj()"/>

</body>

 

</html>

bb.htm

 

[html] view plaincopyprint?<html>  

  

<head>  

  

<title>子窗口</title>  

<script language="javascript" type="text/javascript">  

    //傳值函數  

    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" onclick="chparentval()" value="從子窗口中往父窗口傳值"/><br/>  

  

<input type="button" value="子窗口向父窗口傳遞對象" onclick="fcobj()"/>  

</body>  

  

</html>  

 

<html>

 

<head>

 

<title>子窗口</title>

<script language="javascript" type="text/javascript">

    //傳值函數

    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" onclick="chparentval()" value="從子窗口中往父窗口傳值"/><br/>

 

<input type="button" value="子窗口向父窗口傳遞對象" onclick="fcobj()"/>

</body>

 

</html>

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *