开发者

Closing forms after successful submission Rails 3

I have a form in my rails 3 app that is used to create new tags. This page is opened in a new window and I would like for that window to close after a successful submission of a new tag. How should I go about doing that.

I tried <%= f.submit "Create Tag", :onclick => "window.close()" %> and that didn't work - it still followed through with the redirection.

How might I redirect to a javascript file that would close the window?


Here I tried to redirect to another html page, but it still doesn't close when I use rails, even though it works when I just load it manually.

> <!DOCTYPE html> <html>   <head>
&开发者_如何转开发gt;     <meta http-equiv="Content-type" content="text/html; charset=utf-8">  
> </head>
> 
>   <body id="sample"
> onload="window.close()">
>     This page was meant to close itself immediately using javascript.
> If it has not, please close it
> manually.   </body> </html>


You can use render :text => '<script type="text/javascript"> window.close() </script> in your controller to close the window afterwards.

An alternative solution could be render :action => "window_closer" with windows_closer.html.erb being a HTML file with the same code (and maybe a body and a "Please close window now" text).


I used the best answer on this forum and it seems to work ... I'm not quite sure why.

http://www.google.com/support/forum/p/Chrome/thread?tid=23c03746e3aa03f9&hl=en

window.open('', '_self', '');
window.close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜