Thursday, July 7, 2011

Open multiple links / windows in a single click

A reader asked if she can make a navigation tab open more than one link when clicked. The answer is YES it can be done, with the help from a small Javascript.
(Now if you come here trying to find out how YOU can open multiple links on pages you visit, try Snap Links, a  Firefox addon.)
First let’s look at an HTML code for a regular anchor tag <a>:

<a href="YOUR_URL" target="_blank">Link text</a>

When clicked, this code will open YOUR_URL in a new window. To add another link, just add the code below before “>” in the opening tag:
onclick="window.open(&quot;YOUR_2nd_URL&quot;);"


It will open YOUR_2nd_URL in a second new window. To add more links, simply add more window.open(); before the closing quotation mark.
So if you were to open three links, your anchor will look like this:



<a href="YOUR_URL" target="_blank" onclick="window.open(&quot;&quot;YOUR_2nd_URL&quot;&quot;); window.open(&quot;&quot;YOUR_3rd_URL&quot;&quot;);">Link text</a>



No comments:

Post a Comment