从弹出窗口的JavaScript传递字符串到父窗口

问题描述:

我有一个JavaScript函数,看起来像这样。我需要帮助将这些值从弹出窗口的JavaScript传递到父窗口。我知道,我必须使用从弹出窗口的JavaScript传递字符串到父窗口

window.opener.document.getelementbyD("ID Of TextBox"); 

方法在我的孩子aspx页面,但textbox是内其他用户的控制。我该怎么做?

function(PersonName, EmailID){ 
    //assign these values to text boxes of a parent window 
    //the text boxes of parent window are inside of control 
} 

问候
-Vishu

+1

我是新来的,请有人可以帮助我吗? – 2013-03-05 07:04:30

+0

http://jsfiddle.net/DerekL/dHxEP/ – 2013-03-05 07:07:32

你可以写两个简单的JS-功能。一个(setValues)在你的“父窗口”窗口中​​,这个窗口会被弹出窗口调用。还有一个在你的弹出窗口(setValuesToParent)中收集父窗口中的值和调用函数。请不要忘记,这个例子是用普通的JavaScript编写的,并没有使用任何asp.net的东西。

// in your pop up 
function setValuesToParent() { 
    var PersonName= document.getElementById('PersonNameInPopUp').value; 
    var EmailID = document.getElementById('EmailIDInPopUp').value; 
    window.opener.setValues(PersonName, EmailID); // this is the important line 
} 



// in your parent window 
function setValues(PersonName, EmailID) { 
    document.getElementById('PersonName').value = PersonName; 
    document.getElementById('EmailID').value = EmailID; 
}