1

I am trying to open multiple new tabs when a link is clicked, is this possible using the link_to helper? If not what is the best way to do this

Laura M
  • 343
  • 5
  • 20
  • 1
    It seems that javascript is the correct way to go... – xlembouras May 13 '14 at 14:15
  • 4
    For to open one new tab,you can have `:target => '_blank'` in your `link_to`.For multiple tabs,not possible. – Pavan May 13 '14 at 14:17
  • It *is* possible with javascript, as xlembouras suggests. But not possible without :) See http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript or http://stackoverflow.com/questions/20845132/open-multiple-tabs-with-jquery – Max Williams May 13 '14 at 14:24
  • However, as someone asks in the second of my linked posts, this may not be a good idea. Opening one new tab is fair enough, though some would argue that even this should only be done at the decision of the user, ie by them right clicking and choosing "open in a new tab". But opening multiple tabs feels like spammy nastiness, even if they all go to your own website. – Max Williams May 13 '14 at 14:27
  • Can you give us some context? EG why do you need multiple tabs opened? – Richard Peck May 13 '14 at 15:49

1 Answers1

1

Since the link_to helper is just generating HTML, that's not going to do it for you. You're going to need to use javascript. Something to the effect of:

<script type='text/javascript'>
  document.getElementById("test").onclick = function() {
    window.open("http://www.google.com", '_blank');
    window.open("http://www.p3php.in", '_blank');
  }
</script>
kddeisz
  • 5,162
  • 3
  • 21
  • 44