Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Last active January 2, 2016 10:19
Show Gist options
  • Save ryanburnette/8289544 to your computer and use it in GitHub Desktop.
Save ryanburnette/8289544 to your computer and use it in GitHub Desktop.
Be smart about targets. Use jQuery to add target="_blank" when the destination is not part of the current site.
function () {
$('a[href^="http://"], a[href^="https://"]')
.not('a[href*="' + window.location.hostname + '"]')
.attr('target','_blank')
;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment