It’s easy to forget to add that target=”_blank” each time, and even more difficult to remind clients to select that option in your WYSIWYG!

In a lot of websites I develop we use jQuery – and one of the things I place at the bottom of every website is a snippet to add target=”_blank” to every external link tag.

The jQuery/JavaScript


$(document).ready(function(e){
 $("a[href^='http://'],a[href^='https://']").filter(function()
 {
  return this.hostname && this.hostname !== location.hostname;
 }).attr('target','_blank');
});