绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
Pass value from child popup window to parent page
2020-01-07 18:02:15

Here Mudassar Ahmed Khan has explained how to pass value from child popup window to parent page window using JavaScript.

The child popup window must be opened using JavaScript window.open function. And in such case we can access the parent page controls using JavaScript window.opener instance.

In this article I will explain how to pass value from child popup window to parent page window using JavaScript.
The child popup window must be opened using JavaScript window.open function. And in such case we can access the parent page controls using JavaScript window.opener instance.
 
Parent Page
Inside the Parent Page I have placed a TextBox which is read-only and a button to open the child popup window using the SelectNameJavaScript function.
复制代码
<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 popup;
    function SelectName() {
        popup = window.open("Popup.htm", "Popup", "width=300,height=100");
        popup.focus();
    }
</script>
复制代码
Popup Child Window Page
The Popup Child Window Page has a DropDownList to choose the name of the person and a button which when clicked calls the SetNameJavaScript function.
This function uses the reference of window.opener property and finds the Parent Page txtName TextBox using document.getElementById method of JavaScript and sets the value selected through the DropDownList to it.
复制代码
<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>
复制代码
In similar way you can access other controls too of the Parent Page from the Child Popup Window Page

Pass value from child popup window to parent page window using JavaScript

 
Demo
refernce:
http://www.aspsnippets.com/Articles/Pass-value-from-child-popup-window-to-parent-page-window-using-JavaScript.aspx

分享好友

分享这个小栈给你的朋友们,一起进步吧。

JAVA玩具小屋
创建时间:2019-08-16 16:54:49
分享程序开发方面的小经验,思考一些比较简单易懂的技术问题
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

栈主、嘉宾

查看更多
  • Yios5092
    栈主

小栈成员

查看更多
  • 栈栈
  • coyan
  • 25minutes
  • ?
戳我,来吐槽~