基本html页面和弹出窗口之间的数据交换

时间:2012-08-22 16:40:51

标签: javascript html popup

我有这个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获取值“初始数据” - &gt; document.form1.initialdata.value以及如何从popup.php复制 - &gt; index.php的document.formname.popupdata.value - &gt; document.form1.initialdata.value ??

1 个答案:

答案 0 :(得分:1)

使用

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

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

window.opener alternatives