Reputation:
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 => <name of window> }
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.
Upvotes: 2
Views: 2526
Reputation: 4639
: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.
Upvotes: 2
Reputation: 1386
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();" %>
Upvotes: 0
Reputation: 38529
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.
Upvotes: 0
Reputation: 16849
The popup window can be closed using the onClick html event as follows:
<%= submit_tag "Go!", {:onClick => "window.close()"} %>
Upvotes: 0