Return to Snippet

Revision: 31005
at August 27, 2010 04:52 by scribbleitdesigns


Updated Code
$(document).ready (function() {
   // Activate on links with rel attribute set to ext
   $('a[rel=ext]').click (function() {
      // Add target=_blank attribute to link when clicked
      $(this).attr('target','_blank');
   });
});

/* Usage 
 * simply write your links like this:
 * <a href="url_here" rel="ext" title="title_here">LINK TEXT</a>
 */

Revision: 31004
at August 27, 2010 04:49 by scribbleitdesigns


Initial Code
$(document).ready (function() {
   // Activate on links with rel attribute set to ext
   $('a[rel=ext]').click (function() {
      // Add target=_blank attribute to link when clicked
      $(this).attr('target','_blank');
   });
});

Initial URL

                                

Initial Description
There are many ways to have jQuery open external links for you. Some depend on relative URL\'s for internal links and absolute URL\'s for external links. Some analyze the link to see if it matches your domain. These are great but can sometimes be confusing for those new to jQuery and web development. There is a quick way that you can use and the only requirement is add \'ext\' to the [rel] attribute...

Initial Title
Opening external links in a new window

Initial Tags
jquery, links

Initial Language
jQuery