34

So here's a simple but interesting question, how can I open multiple links using single <a> element?

Using this only opens the first href

<a href="http://www.google.com" href="http://www.yahoo.com" target="_blank">Click Here</a>
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Acidic Cloud
  • 597
  • 1
  • 7
  • 15

2 Answers2

48

You can certainly try this

Demo

<a href="http://www.microsoft.com" target="_blank" onclick="window.open('http://www.google.com'); window.open('http://www.yahoo.com');">Click Here</a>
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
1

I searched for that but unfortunately all methods I found don’t work. I have one way to that with JS (but one linkwill open in the current tab):

HTML Code:

<a id="myId">go</a>

JS Code:

myId.onclick = function(){
   open('https://www.example1.com');
   location.href = ('https://www.example2.com');
}

So here it will open example1.com in another tab.

Then in the current tab, will open example2.com

Note: The order of JS Lines is required otherwise it will not work.

muaadh
  • 51
  • 4