You forgot to call transferText()
After calling transferText() the text was transferred...

<html>
<head>
<script type="text/javascript">
function init()
{
    popupWin = window.open('','popupWin','');
    popupWin.document.writeln('<html><head><title>test</title></head><body><form><input type="text" id="popupTextBox"/></form></body></html>');
    popupWin.document.close();
    popupText = popupWin.document.getElementById("popupTextBox");
    parentText = document.getElementById("parentTextBox");
    transferText();
}
function transferText()
{
    popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox"/>
<input type="button" onclick="init();"/>
</body>
</html>
Answer from Fabian N. on Stack Overflow
๐ŸŒ
SitePoint
sitepoint.com โ€บ javascript
Pass values between popup and main window - JavaScript - SitePoint Forums | Web Development & Design Community
May 31, 2003 - The user can click on the needed row and a variable is being passed on to the main window. The form in the main window is being submitted so details are being filled in with help of the passed variable.
Discussions

how to pass value to pop up window using javascript function? - Stack Overflow
I want to open new window from existing form.When I am clicking on new window in form then new form should open with results of value entered,but new window form is opening with main page,not able ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 20, 2012
Pass Variable to a Popup Window using Javascript - Stack Overflow
I need to pass some text from the current page to a popup window without going for a server hit. The information (herewith represented by 90) is already available in the parent form (it's like a More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - How to pass data to parent window from popup window? - Stack Overflow
How can I pass some data or call a function on the parent window from a popup window? The user will click a link which will open a popup on the same website, once he is finished with the popup, I ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 22, 2017
Javascript Passing value from a popup window to its parent window - Stack Overflow
I'm new in javascript and I'm stuck here. Let's say I have a parent window and it has an input field as well as a button that opens a popup window. This popup window contains Images. I just need t... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Daily Dev Tips
daily-dev-tips.com โ€บ posts โ€บ javascript-sending-data-between-windows
JavaScript sending data between windows
September 9, 2022 - ... You might also have spotted I set this new window as a variable. We have seen this to send data with the other button. To send the data to this new popup window, we need to create the sendMessage function.
Top answer
1 of 2
37

The window.opener object is what you're looking for, used it from within your popup like so to call the a function of the parent window:

window.opener.yourFunc() 
2 of 2
5

Here is a fun and easy demo that is heavily inspired by this answer to a similar question (but modified for my own purposes to help investigate the most difficult bug of my career).

Create 2 files (in the same directory) as follows:

parent.html

<button type="button" onclick="popup('popup.html', '', 800, 200);">Add My Card</button>
=&gt;
<span id="retrievedData">No data yet.</span>    
<script>
    function popup(url, title, width, height) {
        var left = (screen.width / 2) - (width / 2);
        var top = (screen.height / 2) - (height / 2);
        var options = '';    
        options += ',width=' + width;
        options += ',height=' + height;
        options += ',top=' + top;
        options += ',left=' + left;    
        return window.open(url, title, options);
    }

    function setData(data) {
        console.log(data);
        var strData = JSON.stringify(data);
        document.getElementById('retrievedData').innerHTML = strData;
        var requestBinUrl = 'http://requestb.in/18u87g81';
        window.location.href = requestBinUrl + '?data=' + strData;
    }
</script>

popup.html

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="popupForm" name="f">    
    <select id="urlField" name="url">
        <option>
            http://date.jsontest.com/
        </option>
        <option>
            http://time.jsontest.com/
        </option>
        <option>
            http://md5.jsontest.com/?text=HereIsSomeStuff
        </option>    
    </select>
    <div><input type="submit" /></div>    
</form>
<script>
    $('#popupForm').submit(function(e) {
        e.preventDefault();
        var url = $('#urlField').val();
        console.log(url);
        $.ajax({
            url: url
        }).then(function(data) {
            console.log(JSON.stringify(data));
            window.opener.setData(data);
            window.close();
        });
    });    
</script>
Find elsewhere
๐ŸŒ
ASPSnippets
aspsnippets.com โ€บ Articles โ€บ 1102 โ€บ Pass-Send-value-from-Parent-page-window-to-Child-popup-window-using-JavaScript
Pass Send value from Parent page window to Child popup window using JavaScript
April 19, 2021 - The child popup window must be opened using JavaScript window.open function. The window.open function returns the reference of the opened Child popup window using which the elements and controls ...
๐ŸŒ
Rumkin
rumkin.com โ€บ reference โ€บ web โ€บ popup-window
Passing Data To/From Popup Window
First, make a ghost form that will be used to pass data into the popup. <form name=ghost method=post target="the_target_window" action="/the/destination.php"> <input type=hidden name="data" value=""> </form> Mix in a little JavaScript.
๐ŸŒ
Reddit
reddit.com โ€บ r/javascript โ€บ passing data from parent to child in a window.open situation.
r/javascript on Reddit: Passing data from parent to child in a window.open situation.
February 29, 2012 -

Bear with me, I've new to Javascript.

I'm trying to create a little 'share' bookmarklet but cannot pass the data from the parent document to the popup's elements. The popup's input fields are blank.

What am I missing?!

Here's my parent script:

var title = document.title;
var url = window.location.href;
var popForm;

function get_elements() {
    formObject = popForm.document.forms["link_form"];
    formObject.elements["id_title"].value = title;
    formObject.elements["id_url"].value = url;
    }

function bookmark() {

    popForm = window.open("form.html","aWindow","height=500,width=400");
    popForm.window.onload=get_elements
    }

And my child just look slike this:

Title:</br>		
<input id="id_title" type="text" name="title" maxlength="50" value="" />
</p>
Description:</br>
<textarea id="id_descrip" rows="10" cols="40" name="descrip"></textarea>
</p>
Url: <input id="id_url" type="text" name="url" maxlength="100" title="" />
</p>
<input type="submit" value="Submit" />
Top answer
1 of 4
3
If you wish to pass data into a child window, you may modernly use postMessage
2 of 4
1
So here's a couple things I'm not sure about, and a few things that I know are problematic. Instead of using the document.forms["x"].elements["y"] the standard way to access form elements is document.getElementById("y"). That makes it simpler. I'm not sure how the child page is going to handle the global variable "(PopForm)". You could do something like, using a closure to create the variable in there to be sure, but that sounds like it might be overcomplicating your solution. Setting the onload event from the parent can be... finicky I've found. I think a better solution would be to put an oload event in your child that calls your method form the parent, and grab the data you want from the parent, I think that will be less confusing. You just need to make sure that the function in the parent will be accessible to the child. var title = document.title; var url = window.location.href; var popForm; function get_elements() { popForm.document.getElementById("id_title").value = title; popForm.document.getElementById("id_url").value = url; } function bookmark() { popForm = window.open("form.html","aWindow","height=500,width=400"); popForm.window.onload=get_elements } window.get_elements_accessor = get_elements; Now on you inner page set it up like this. Title: Description: Url: I think it's more clear what's going on if you do it this way than trying to to use global variables from the opener in the opened window. Give it a shot, I haven't tested the code there though, so let me know where I made the eventual mistakes ;).
๐ŸŒ
Bytes
bytes.com โ€บ home โ€บ forum โ€บ topic โ€บ javascript
passing data from parent window to popup - Javascript
June 27, 2008 - hi forum i have read a lot of articles regarding passing data from popup to parent up but i m looking for the opposite that is from parent to popup window pls help me in this regard i have three input fields in parent window and three in popup window parent.htm ... <script language="JavaScript"> function newWindow(file,window) {msgWindow=open(file,window,'scrollbars=yes,resizable=no,width=550,height=400'); if (msgWindow.opener == null) msgWindow.opener = self; } </script> <input type="button" value="Search" onClick="newWindow('popup.htm','window2')"> <form name="inputform1" > <table><tr><td>St
๐ŸŒ
StudySection
studysection.com โ€บ home โ€บ open a popup window with a window.open() passing parameters as โ€˜postโ€™
Open a popup with a window.open passing parameter - SS Blog
January 13, 2023 - This can be achieved by creating an Html page with the form submit with post method in the application which is and using action attribute with the post URL, but here the target is without creating the Html page, create on the fly Html content ...
๐ŸŒ
Javascriptbit
javascriptbit.com โ€บ transfer-data-between-parent-window-and-popup-postmessage-api
Send data from parent window to child popup window - PostMessage API | JavaScriptBit
/* Step 1 : Open popup */ const popup = window.open("https://google.com", "_blank"); /* Step 2 : Add message event listener in popup window Open the console of the newly opened window and add this code */ window.addEventListener("message", function(event) { if (typeof(event.data) === "string") { alert("Hello from the other side!