JS window 对象 open方法弹窗实现父子窗口中的参数传递

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhulei12345/article/details/48342161

JS window 对象 open方法弹窗实现父子窗口中的参数传递

注:需要将页面加载到服务器中


父页面parent.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            Name:&nbsp;
        </td>
        <td>
            <input type="text" id="txtName" readonly="readonly" />
        </td>
        <td>
            <input type="button" value="Select Name" onclick="SelectName()" />
        </td>
    </tr>
</table>
<script type="text/javascript">
    var openUrl = "Popup.htm";//弹出窗口的url
    var iWidth=800; //弹出窗口的宽度;
    var iHeight=600; //弹出窗口的高度;
    var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
    var popup;
    function SelectName() {
        popup = window.open(openUrl,"","height="+iHeight+", width="+iWidth+", top="+iTop+", left="+iLeft);
        popup.focus();
        return false
    }
</script>
</body>
</html>

子页面Popup.htm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
<select name="ddlNames" id="ddlNames">
    <option value="Mudassar Khan">Mudassar Khan</option>
    <option value="John Hammond">John Hammond</option>
    <option value="Mike Stanley">Mike Stanley</option>
</select>
<br />
<br />
<input type="button" value="Select" onclick="SetName();" />
<script type="text/javascript">
    function SetName() {
        if (window.opener != null && !window.opener.closed) {
            var txtName = window.opener.document.getElementById("txtName");//获取父窗口中元素,也可以获取父窗体中的值
            txtName.value = document.getElementById("ddlNames").value;//将子窗体中的值传递到父窗体中去
        }
        window.close();
    }
</script>
</body>
</html>
展开阅读全文

没有更多推荐了,返回首页