我有一个弹出窗口,其中包含一个为报告收集数据的表单。当我在该窗口中单击提交时,我希望它关闭弹出窗口,并在调用弹出窗口的原始窗口中打开报告。
我想我可以通过使用在正确的窗口中打开报告
{ :target => <name of window> }
中form_tag
,但我不知道如何确定或设置原始窗口的名称。
我也不知道如何关闭弹出窗口。
我有一个弹出窗口,其中包含一个为报告收集数据的表单。当我在该窗口中单击提交时,我希望它关闭弹出窗口,并在调用弹出窗口的原始窗口中打开报告。
我想我可以通过使用在正确的窗口中打开报告
{ :target => <name of window> }
中form_tag
,但我不知道如何确定或设置原始窗口的名称。
我也不知道如何关闭弹出窗口。
: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.
这对初学者来说如何?
# The submit button in your child window's view:
<%= button_to_function 'Save', "$('my_form').submit(); window.opener.location.reload(); window.close();" %>
可以使用 onClick html 事件关闭弹出窗口,如下所示:
<%= submit_tag "Go!", {:onClick => "window.close()"} %>
尝试这个:
function fclosepopup(){
window.opener.location.replace="URL";
window.close();
}
它将关闭当前窗口并将您带到父窗口中的下一页。