<p>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.</p>

<p>I think I can open the report in the correct window by using</p>

<pre><code>{ :target =&gt; &lt;name of window&gt; }
</code></pre>

<p>in the <code>form_tag</code>, but I don't know how to determine or set the name of the originating window.</p>

<p>I also don't know how to close the popup window.</p>

[{'answer_id': 36065, 'author': 'Craig', 'author_id': 1611, 'author_profile': 'https://Stackoverflow.com/users/1611', 'pm_score': 0, 'selected': False, 'text': '<p>How is <a href="http://railsforum.com/viewtopic.php?id=17785" rel="nofollow noreferrer">this</a> for starters?</p>\n\n<pre><code># The submit button in your child window\'s view:\n&lt;%= button_to_function \'Save\', "$(\'my_form\').submit(); window.opener.location.reload(); window.close();" %&gt; \n</code></pre>\n'}, {'answer_id': 36126, 'author': 'Brent ', 'author_id': 3764, 'author_profile': 'https://Stackoverflow.com/users/3764', 'pm_score': 0, 'selected': False, 'text': '<p>The popup window can be closed using the onClick html event as follows:</p>\n\n<pre><code>&lt;%= submit_tag "Go!", {:onClick =&gt; "window.close()"} %&gt;\n</code></pre>\n'}, {'answer_id': 159813, 'author': 'Steropes', 'author_id': 21872, 'author_profile': 'https://Stackoverflow.com/users/21872', 'pm_score': 2, 'selected': False, 'text': '<p><code>:target =&gt;</code> adds the html attribute target to the link.  This opens up a new window and names the new window the target.</p>\n\n<p>You have to use javascript or Ajax to redirect the old page,</p>\n\n<pre><code>window.opener.location.href="http://new_url";\n</code></pre>\n\n<p>and then close the old window.</p>\n\n<pre><code>window.close();\n</code></pre>\n\n<p>This can be done either through the rjs file or directly in the javascript.</p>\n'}, {'answer_id': 445882, 'author': 'praveenjayapal', 'author_id': 38172, 'author_profile': 'https://Stackoverflow.com/users/38172', 'pm_score': 0, 'selected': False, 'text': '<p>Try this:</p>\n\n<pre><code>function fclosepopup(){\nwindow.opener.location.replace="URL";\nwindow.close();\n}\n</code></pre>\n\n<p>It will close the current window and bring you to the next page in the parent window.</p>\n'}]
['https://Stackoverflow.com/questions/36058', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']