Search the blog

This code makes external links open in a new window. I find this useful when dealing with, for example, Markdown — where you can’t set the target attribute.

$('a[href^="http://"], a[href^="https://"]').each(function() {

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

});

Note: this assumes you are using relative links internally (as you should do).

Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.