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 Overflowyou can do it like this:
In parent:
function openChildWin() {
var childWin = window.open("childWin.html", "_blank", "height=400, width=550, status=yes, toolbar=no, menubar=no, location=no,addressbar=no");
}
function setValue(val1) {
// do your logic here
}
in popup:
function OKClicked() {
window.opener.setValue(true);
}
Use below code and replace test with your element Id.
var parentDoc = window.opener.document;
parentDoc.getElementById("test").value = document.getElementById("test").value;
http://www.javascripter.net/faq/openinga.htm
The return value is the reference to your new window. You can use this reference later, for example, to close this window (winRef.close()), give focus to the window (winRef.focus()) or perform other window manipulations.
Window.open either returns a handle to the new window opened or null, it will not tell you if the page within the window loaded successfully. If you where opening an html page (from the same domain) you could use this to look into the document
var newWin = window.open();
if(newWin == null) {
alert("darn");
}
newWin.document.getElementById("anElement").innerText = "Fish";
In the popup, hook an onclick event on your submit button so it executes before the submit. Then in the onclick handler do:
window.opener['dataitem'] = <your return value>;
Then after the submit, your parent window will have that value, and you can access it like this:
var somevariable = window['dataitem'];
function setColor(color){ if (opener && !opener.closed){ opener.document.theForm.theField.value = color; opener.focus(); } window.close(); } ... <td width="30" bgcolor="#FFFF00" onclick="setColor(this.bgColor)"> </td>
Read more at http://www.codingforums.com/showthread.php?t=61319#gkH9pd6gdgvxYqQZ.99