[ jQuery ] Target Blank Links


 / Published in: JavaScript
 

Open a new window without using target="_blank" for XHTML 1.1. Need jQuery Framework : http://jquery.com/

  1. $('a[@rel$='external']').click(function(){
  2. this.target = "_blank";
  3. });
  4.  
  5. /*
  6.   Usage:
  7.   <a href="http://www.lepinskidesign.com.br/" rel="external">lepinskidesign.com.br</a>
  8. */

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: eisabai on November 15, 2010

You can also do this:

$('a[rel=external]').attr('target', '_blank');

More useful jQuery snippets at http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/

Posted By: jondiscipulo on March 2, 2011

Make sure to put this code below your links to work.

Posted By: Snowalker on November 30, 2011

just wondering if I want to make rel="nofollow" the links using this method if the Googlebot will really consider it. Anyone?

Posted By: Snowalker on November 30, 2011

here even more simplified:

$('a').attr('target', '_blank');

and for rel=nofollow: $('a').attr('rel', 'nofollow');

Posted By: Snowalker on November 30, 2011

here even more simplified:

$('a').attr('target', '_blank');

and for rel=nofollow: $('a').attr('rel', 'nofollow');

You need to login to post a comment.