Rails: How to use “_blank” or “_new” in Rails

后端 未结 4 936
再見小時候
再見小時候 2020-12-16 12:43

In HTML, if I wanted a link to open in a new window, I\'d adopt target=\"_blank\" like this:



        
相关标签:
4条回答
  • 2020-12-16 13:15

    you can also do target: :_blank if you prefer to use a symbol

    0 讨论(0)
  • 2020-12-16 13:20

    I think it's like this

    <%= link_to image_tag('img.png'), 'http://www.website.com', target: '_blank' %>
    

    See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

    0 讨论(0)
  • 2020-12-16 13:23

    you can remove the default action of the link in js as

    $('#button-id').click(function(e){
      e.preventDefault();      
    });
    

    The preventDefault() function prevents the default action of the event

    0 讨论(0)
  • 2020-12-16 13:36

    For anyone wondering how to achieve this when passing a block:

    <%= link_to(product.link, target: '_blank') do %>

    0 讨论(0)
提交回复
热议问题