2

我有这个 index.php 文件;

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Proj</title>
        <script type="text/javascript">
            function openWindow() {
                window.open("popup.php", "popup_id", "scrollbars=no,resizable,width=200,,left=300,top=300,height=200");
            }
        </script>
    </head>
    <body>
        <form name="form1" action="">
            <input name="initialdata" type="text" value="initial data" />
            <input type="button" value="Send" onClick="openWindow()" />
        </form>
    </body>
</html>

和这个 popup.php 文件

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>popup</title>
        <script type="text/javascript">
            function putData() {
                //How to copy from that file -> document.formname.popupdata.value to 
                //index.php -> document.form1.initialdata.value???
                window.close();
            }
            function loadData() {
                //how to get the value "initial data"
                //from index.php -> document.form1.initialdata.value????????????
            }
        </script>
    </head>
    <body onLoad="loadData();">
        <form name="formname" action="">
            <input name="popupdata" type="text" value="" />
            <input type="button" value="Send" onClick="putData()" />
        </form>
    </body>
</html>

如何从 index.php -> document.form1.initialdata.value 获取值“初始数据”以及如何从 popup.php -> document.formname.popupdata.value 复制到 index.php -> document.form1 .initialdata.value??

4

1 回答 1

1

使用

window.opener.document.getElementsByName("initialdata")[0].value;

不过,这可能不适用于每个浏览器。有关详细信息,请参阅此问题:

window.opener 替代品

于 2012-08-22T16:44:10.280 回答