Open Pop-Up window in Rails on clicking link

情到浓时终转凉″ 提交于 2019-12-11 08:24:25

问题


I want to open a pop-up window on click of 'link', then show some data there and close it.

I am using 'link_to' to create 'link'. The part of code looks as:

<%= link_to 'Display Links', :controller=>'aaa', :action=> 'xyz_links', ....... %>

回答1:


Previously, in rails2.3.x you could just do:

link_to "foo", foo_path(foo), :popup => true

But now in Rails3, this option has been deprecated

Another option is to use the Rails 3 unobtrusive way of event
delegating those links:

First add an attribute "data-popup" to your link_to if you want it to open
in a new window

Then if you are using the jquery adapter, add to application.js inside the document
ready handler:

$('a[data-popup]').live('click', function(e) { 
    window.open($(this).attr('href')); 
    e.preventDefault(); 
}); 

Or with the prototype adapter, use this code inside the document ready
handler:

document.on("click", "a[data-popup]", function(event, element) { 
    if (event.stopped) return; 
    window.open($(element).href); 
    event.stop(); 
}); 

You can find the same discussion here: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/e1f02d9e0977071b/814d69e4d56cea65?show_docid=814d69e4d56cea65&utm_medium=twitter&pli=1




回答2:


I haven't tried this but have this in ruby docs:

<%= link_to name, url, :popup => ['dialog name','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'] %>

pls check at

http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to#29-Window-open-a-dialog-of-no-menu-no-status-have-scroll



来源:https://stackoverflow.com/questions/8846979/open-pop-up-window-in-rails-on-clicking-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!