網頁中window.open 彈出 父頁面和子頁面數值交互


//首先建立一個父頁面

<!doctype html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>父頁面</title>

<script>

  function tanchu(){

    window.open("son.html","ziyemian","width=300,height=400,top=200,left=300,toobar=no,menubar=no,scrollbars=no,location=no,status=no");

  }

  function reTurn(){

    return document.getElementById("aaa");

  }

</script>

</head>

<body>

  <input value="提交" id ="button" type="button" onclick="tanchu()"/>

  <input type="text" id="bbb">

  <input type="text" id="ddd" value="123456">

</body>

</html>

 

//son.html

<!doctype html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<title>子頁面</title>

</head>

<body>

  <script>

    function aaa(){

      window.opener.document.getElementById("bbb").value="123123123";//向父頁面傳值

      //獲取父級頁面的的值

      //window.opener.a();   調用父級頁面的方法

      alert(window.opener.a().value);

      window.opener.location.reload(); //刷新父級頁面

    }

  </script>

  <input type="button" id="button" value="提交" onclick="aaa()">

  <input type="button" value="返回" onclick="top.close()">  //點擊返回按鈕關閉 頁面

</body>

  <script>

    //當頁面的關閉的時候,執行的方法

    window.onbeforeunload = function(){

      window.opener.document.getElementById("bbb").value="123123123qweqwe123";

    }

</script>

</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM