Skip to content

Instantly share code, notes, and snippets.

@scottlee
Created May 15, 2013 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottlee/5584524 to your computer and use it in GitHub Desktop.
Save scottlee/5584524 to your computer and use it in GitHub Desktop.
All external links in new window.
<script>
$(document).ready(function() {
$('a[href]')
.filter(function(){
return ($(this).attr('href').match(new RegExp('^https?|ftp')));
})
.filter(function(){
return (! $(this).attr('href').match(new RegExp('^(https?|ftp):\/\/'+location.hostname)));
})
.attr('target', '_blank');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment