Home »

Getting strict on External links

15. November 2009 by thebeebs 0 Comments

jquery If you want to have all links in your document that point to external sites open up in a new window then you’ll realise you can no longer use target=”_blank”… well that’s if you want to conform to XHTML strict. The Jquery Snippet below could solve your problem.

 

 

 

$.expr[':'].external = function(obj)
{    
return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname);
};

$(document).ready(function() {
$('a:external').attr('target', '_blank');
});

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading