views:

828

answers:

4

I have a popup window containing a form which gathers data for a report. When I click submit in that window, I want it to close the popup, and open the report in the original window that called the popup.

I think I can open the report in the correct window by using { :target => } in the form_tag, but I don't know how to determine or set the name of the originating window.

I also don't know how to close the popup window.

A: 

How is this for starters.

The submit button in your child window's view:

<%= button_to_function 'Save', "$('my_form').submit(); window.opener.location.reload(); window.close();" %>

Craig
A: 

The popup window can be closed using the onClick html event as follows:

<%= submit_tag "Go!", {:onClick => "window.close()"} %>
Brent
+2  A: 

:target => adds the html attribute target to the link. This opens up a new window and names the new window the target.

You have to use javascript or Ajax to redirect the old page,

window.opener.location.href="http://new_url";

and then close the old window.

window.close();

This can be done either through the rjs file or directly in the javascript.

Steropes
A: 

Hi

try this

function fclosepopup(){ window.opener.location.replace="URL"; window.close(); }

It will close the current window and bring you to the next page in the parent window

praveenjayapal