"Facebook", :target => "_blank"), "htt-6ren">
gpt4 book ai didi

ruby-on-rails - rails : Open link in new tab (with 'link_to' )

转载 作者:数据小太阳 更新时间:2023-10-29 06:17:14 26 4
gpt4 key购买 nike

我有这个代码:

<%= link_to image_tag("facebook.png", :class => "facebook_icon", :alt => "Facebook", :target => "_blank"),                 
"http://www.facebook.com/mypage" %>

当用户点击链接时,如何在新标签页中打开它?

最佳答案

target: :_blank 参数应该是link_to 的参数,而你把它放在image_tag 参数中。像这样修改您的代码:

<%= link_to image_tag("facebook.png", class: :facebook_icon, alt: "Facebook"), "http://www.facebook.com/mypage", target: :_blank %>

或者用一个 block :

<%= link_to "http://www.facebook.com/mypage", target: :_blank do %>
<%= image_tag("facebook.png", class: :facebook_icon, alt: "Facebook") %>
<% end %>

关于ruby-on-rails - rails : Open link in new tab (with 'link_to' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12133894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com