Search the blog

To make all external links open in a new window use this jQuery code:

$('a[href^="http://"], a[href^="https://"]').attr('target','_blank');

If you only wish to apply this to certain links then change the jQuery selectors accordingly. For example:

$('div.content a[href^="http://"], div.content a[href^="https://"]').attr('target','_blank');

This will only apply the change to links within a div.content element.

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