Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Popup Window Return Value to Parent

How can I accomplish the following using jQuery: Open a popup window that returns a value to the parent window when a link in the child window is clicked, close the child window, and then have the parent automatically submit a form based on the value returned?

I realize that the jQuery Dialog is a popular solution, but I require a popup window because the window's contents need to be navigable, and I want to avoid using an iframe in the jQuery Dialog.

The popup window is going to be used to collect more than one value, ultimately to be returned as a delimited string to the parent, but this data collection needs to occur prior to the submission of the parent window's form. If there were a standard design pattern for an "Entity Picker", this would be it.

This needs to work in IE8, FF3.6, Safari 4, and Chrome 5.

Thanks, Mark

like image 967
Mark Richman Avatar asked Feb 28 '10 22:02

Mark Richman


People also ask

Can window open return a value?

the pop up window must be able to return a value to the "parent". Typically this value is a Boolean but it could be any simple type (e.g.: string, int, etc.) solution must work even if the URL of the content is from different domain.

What is window returnValue?

Specifies or retrieves the value returned from a modal dialog window. 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.


2 Answers

Here is my solution:

var parent = $(parent.document.body);
$(parent).find('input#valStore').val(theVal);
$(parent).find('form#myForm').submit();
window.close();
like image 122
iman1003 Avatar answered Oct 05 '22 22:10

iman1003


In your newly opened browser window you could try something like

$("#mylink").click(function(){ 
        value = /* get some value */
        window.opener.$("#myform .somehiddenfield").val(value); 
        window.opener.$("#myform").submit();
        window.close(); 
}); 

DISCLAIMER: I haven't tested this in any browser.

like image 32
Rune Avatar answered Oct 05 '22 23:10

Rune