I have two ideas that could help you but the first one is tied to CORS, so you won't be able to use it from different domains at least you can access both services and configure them.

FIRST IDEA:

The first one is related to this native api. You could create on the parent window a global function like this:

window.callback = function (result) {
    //Code
}

As you can see it receives a result argument which can hold the boolean value you need. The you could open the popup using the same old window.open(url) function. The popup's onlick event handler could look like this:

function() {
    //Do whatever you want.
    window.opener.callback(true); //or false
}

SECOND IDEA: Solves the problem

The other idea I got is to use this other native api to trigger an event on the parent window when the popup resolves (better known as cross-document messaging). So you could do this from the parent window:

window.onmessage = function (e) {
    if (e.data) {
        //Code for true
    } else {
        //Code for false
    }
};

By this way you are listening to any posted message on this window, and checking if the data attached to the message is true (the user clicks ok in the popup) or false (the user clicks cancel in the popup).

In the popup you should post a message to the parent window attaching a true or a false value when corresponds:

window.opener.postMessage(true, '*'); //or false

I think that this solution perfectly fits your needs.

EDIT I have wrote that the second solution was also tied to CORS but digging deeper I realized that cross-document messaging isn't tied to CORS

Answer from Augusto Altman Quaranta on Stack Overflow
Top answer
1 of 1
37

I have two ideas that could help you but the first one is tied to CORS, so you won't be able to use it from different domains at least you can access both services and configure them.

FIRST IDEA:

The first one is related to this native api. You could create on the parent window a global function like this:

window.callback = function (result) {
    //Code
}

As you can see it receives a result argument which can hold the boolean value you need. The you could open the popup using the same old window.open(url) function. The popup's onlick event handler could look like this:

function() {
    //Do whatever you want.
    window.opener.callback(true); //or false
}

SECOND IDEA: Solves the problem

The other idea I got is to use this other native api to trigger an event on the parent window when the popup resolves (better known as cross-document messaging). So you could do this from the parent window:

window.onmessage = function (e) {
    if (e.data) {
        //Code for true
    } else {
        //Code for false
    }
};

By this way you are listening to any posted message on this window, and checking if the data attached to the message is true (the user clicks ok in the popup) or false (the user clicks cancel in the popup).

In the popup you should post a message to the parent window attaching a true or a false value when corresponds:

window.opener.postMessage(true, '*'); //or false

I think that this solution perfectly fits your needs.

EDIT I have wrote that the second solution was also tied to CORS but digging deeper I realized that cross-document messaging isn't tied to CORS

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN
The returned reference can be used to access properties and methods of the new context as long as it complies with the same-origin policy security requirements. If the Cross-Origin-Opener-Policy HTTP header is being used, and the document policies are such that the document is opened in a new browsing context group, references to the opened window are severed and the returned object will indicate that the opened window is closed (closed is true).
🌐
W3Schools
w3schools.com › jsref › met_win_open.asp
Window open() Method
var myWindow = window.open("", "MsgWindow", "width=200,height=100"); myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>"); Try it Yourself » · Using the opener property to return a reference to the window that created the new window:
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 996153 › window-open-api-returns-null-although-the-window-i
window.open API returns null although the window is launched. - Microsoft Q&A
September 6, 2022 - I am trying to to open a window using window.open as shown below var dlg = window.open("blank.html", name, args); here although the window is open, the return value dlg is null. blank.html contains only one line of code to set…
🌐
Alibaba Cloud
topic.alibabacloud.com › a › a-simple-example-of-the-return-value-of-js-pop-up-window-_javascript-tips_8_8_20178274.html
A simple example of the return value of JS pop-up window _javascript tips
Value; Window.close (); } </script> <input type= "button" name= "Submit" value= "submitted" onclick= "returnvalue ();" > <input name= "Returntext" type= "text" id= "Returntext" > </p> Supplement: Usage of Window.opener · The use of Window.opener in general usage, is only used to solve the closed window does not prompt pop-up window, but it is more in-depth understanding of the general relatively few.
🌐
Dottoro
help.dottoro.com › ljxdnukm.php
returnValue property (window) JavaScript
Modal dialog windows can be created with the showModalDialog method. The showModalDialog method does not return until the modal dialog is closed. With the returnValue property, the value returned by the showModalDialog method can be retrieved. This property facilitates the communication between the opener and the dialog window.
🌐
WebDeveloper.com
webdeveloper.com › community › 29303-open-popup-and-return-value
Open popup and return value
[b]Parent[/b] [code=php] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Content-Script-Type" content="text/javascript"> <title>Parent Sample</title> <script type="text/javascript"> var newWin; function setHidden(val) { document.forms[0].myHidden.value = val; newWin.close(); if (val == "Y") alert("Submit Form"); else alert("Did not agree"); } function getRadioValue(name) { var s = "script"; if (!newWin || newWin.closed) newWin = window.open('agree.htm','','top=150,lef
🌐
Microsoft Learn
learn.microsoft.com › en-us › archive › msdn-technet-forums › 67962d01-5c18-48d7-b6e8-fdf991349e94
Window.open return value | Microsoft Learn
window.open("../OPCUA/TagBrowser.aspx?OPCdata=" + serverUrl + "&OPCConInfo=" + opcConInf, 'OPCClientWindow', 'width=496,height=400,scrollbars=no'); var retValue = document.getElementById("txtRHS").value; In child window(TagBrowser.aspx) > on click of OK button i am returning value to parent window using below code
Find elsewhere
🌐
Reality Ripple
udn.realityripple.com › docs › Web › API › Window › open
Window.open() - Web APIs
With the built-in popup blockers, you have to check the return value of window.open(): it will be null if the window wasn't allowed to open.
🌐
Blogger
theprofessionalspoint.blogspot.com › 2014 › 04 › how-to-return-value-from-child-window.html
The Professionals Point: How to return value from child window to parent window using window.open in Javascript?
It is very easy to return a value from a child window to parent window which has been opened from parent window using window.open method in Javascript. In many scenarios, it is possible to do some calculations on the child window and parent window need the result of that calculations to perform ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-open-window-close-method
Javascript Window Open() & Window Close() Method - GeeksforGeeks
August 5, 2025 - Return Value: This method creates a new window. Window.close(): This method is used to close the window which is opened by the window.open() method.
Top answer
1 of 1
37

I have two ideas that could help you but the first one is tied to CORS, so you won't be able to use it from different domains at least you can access both services and configure them.

FIRST IDEA:

The first one is related to this native api. You could create on the parent window a global function like this:

window.callback = function (result) {
    //Code
}

As you can see it receives a result argument which can hold the boolean value you need. The you could open the popup using the same old window.open(url) function. The popup's onlick event handler could look like this:

function() {
    //Do whatever you want.
    window.opener.callback(true); //or false
}

SECOND IDEA: Solves the problem

The other idea I got is to use this other native api to trigger an event on the parent window when the popup resolves (better known as cross-document messaging). So you could do this from the parent window:

window.onmessage = function (e) {
    if (e.data) {
        //Code for true
    } else {
        //Code for false
    }
};

By this way you are listening to any posted message on this window, and checking if the data attached to the message is true (the user clicks ok in the popup) or false (the user clicks cancel in the popup).

In the popup you should post a message to the parent window attaching a true or a false value when corresponds:

window.opener.postMessage(true, '*'); //or false

I think that this solution perfectly fits your needs.

EDIT I have wrote that the second solution was also tied to CORS but digging deeper I realized that cross-document messaging isn't tied to CORS

🌐
SitePoint
sitepoint.com › javascript
Return value from a pop-up window - JavaScript
March 31, 2007 - Hello, I have a problem with the popup window. I explain the idea: from the parent window i need some values that are in the db2 database, and when the user for example don’t know the customer code, put in the field the name instead for example “fred”, then i open the popup, where i receive ...
🌐
ASP.NET Forums
forums.asp.net › t › 2047032.aspx
Window.open return value
window.open("../OPCUA/TagBrowser.aspx?OPCdata=" + serverUrl + "&OPCConInfo=" + opcConInf, 'OPCClientWindow', 'width=496,height=400,scrollbars=no'); var retValue = document.getElementById("txtRHS").value; In child window(TagBrowser.aspx) ---> on click of OK button i am returning value to parent window using below code
🌐
CodeProject
codeproject.com › Questions › 582038 › asppluspopuppluswindowplusandplusreturnplusvalue
asp popup window and return value - CodeProject
April 22, 2013 - Free source code and tutorials for Software developers and Architects.; Updated: 30 Apr 2013
🌐
CEF Forum
magpcss.org › ceforum › viewtopic.php
CEF Forum • js window.open return null ILifeSpanHandler:OnBeforePopup
Hello, I have a similar problem to the discussion in viewtopic.php?f=6&t=14109&p=30522&hilit=window.open+window.open+#p30522 I have a JS code that open a window (It is a 3rd party code and I cannot change it) var myWindow = window.open("", "MsgWindow", "width=200,height=100"); The return value of "window.open" is null when I implement the method ILifeSpanHandler:OnBeforePopup () When I tried to set a value to the parameter "out IWebBrowser newBrowser" I got the attache exeption.
🌐
Stack Overflow
stackoverflow.com › questions › 16303598 › returning-value-from-a-window
Returning value from a window - javascript
April 30, 2013 - ... you can use showModalDialog() instead of window.open(), allowing you to set window.returnValue in the popup before close()ing it, returning the value to the showModalDialog call much like prompt() or confirm().