Click here to Skip to main content
15,438,202 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried to pass data from child window to parent window using javascript but parent.returnvalue is not working in chrome. Is there any alternative of parent.returnvalue??

var txtfolioID = document.getElementById('<%= txtfolioID.ClientID %>');
var txtfolioName = document.getElementById('<%= txtfolioName.ClientID %>');

var ret = new Array(Number(txtfolioID.value),

parent.returnValue = ret;

Please help

What I have tried:

I tried

var opener = window.opener;
if (opener) {
 var oDom = opener.document;
 var elem = oDom.getElementById("txtfolio");
   if (elem) {
       elem.value = 'Success';

but still, the child window value doesn't set to parent window.

Console error

Uncaught TypeError: parent.setFolio is not a function
    at OnChoose (Portfolios.aspx?ResourceID=0:187)
    at HTMLInputElement.onclick (Portfolios.aspx?ResourceID=0:1)


var opener = window.opener;
                        if (opener) {

still it's not working
Updated 10-Jan-22 3:37am

1 solution

The returnValue reference looks odd to me. That's either associated with a dialog element, which is still experimental, or the showModalDialog method, which is no longer supported in any modern browser.

If by "child window" you mean you've embedded one page inside another using an iframe, you should be able to create a function in the parent window and call that from the child window:
/* Parent window: */
window.setFolio = function(folioID, folioName) {
    document.getElementById("txtfolio").value = folioName;
parent.setFolio(Number(txtfolioID.value), txtfolioName.value);
NB: Both documents will need to be served from the same origin (protocol, host name, and port number) for the call to work. If you need to make a cross-origin call, you would need to use postMessage[^] instead.
Share this answer
Member 14362033 10-Jan-22 4:30am     CRLF
Hello, yes, you are right. It's showModalDialog. I changed it to to open child popup.
Member 14362033 10-Jan-22 8:12am     CRLF
Hello, I tried with your code but it's not working :(
Richard Deeming 10-Jan-22 8:47am    
Check the developer console in your browser for any errors.
Member 14362033 10-Jan-22 9:05am    
Yes there is an error like parent.setFolio is not a function
Richard Deeming 10-Jan-22 9:07am    
If you've used rather than embedding the page in an iframe, you'll need to use opener instead of parent.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900