SEARCH W7R

Sunday, May 13, 2012

HTML Force Links to Open in New Tab


Sometimes, as a blog writer, it seems counter-productive for you to provide links to other websites and blogs that have similar or better content then your own; however, contrary to ones intuition, providing useful links from your site can build up an audience as well as a new post could.
In other words, sharing your resources with your audience will only benefit your blog or site. A thought crossed my mind after adding more links and resources to my blog. The thought was that when many people read content on the web clicking links to get more indepth information is inevitable, but most viewers do not intend to leave your page. So, I wanted the links on my site that appear in articles and posts to open in a new tab by default.
The knew there must be a way to force links to open in a new tab because you can right click any link and select "Open in new tab". So, after a google or two it was clear that one of the easiest ways to do this was by hiding the bar, instead of actually removing it all together. By using an attribute for the HTML anchor tag, <a>. Here's the original HTML code for a link to google (The first link would open and make you leave this page, but the 2nd link would open the page in a new tab.)

<a href="http://www.google.com/"> Go To Google </a>
Go To Google
<a href="http://www.google.com/" target="_blank"> Go To Google (new tab)</a>
Go To Google (new tab)

1 comment:

Anonymous said...

Thanks from an HTML rookie! This works great.