开发者

link_to multiple links with one click

I am using RoR's link_to. I want both to send a :remote => true link_to which will preform an action on the page without a refresh AND I'd like to open a new page (:target=>"_blank") in a new b开发者_运维百科rowser window.

How can I do both actions in one click?

Thanks!


Suppose you have a link:

<%= link_to "My Link", "/path/for/my/link", :remote => true, :id => "mylink" %>

If you wanted to open the new page after the action is performed, then you can put it in your action's myaction.js.erb file:

window.open("/url_to_open");

However, if you want the new window to open immediately when you click the link, you could add this javascript to intercept the remote call before it's sent to the server (assuming you're using jQuery):

$("#mylink").bind("ajax:beforeSubmit", function(){
  window.open("/url_to_open");
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜