Skip to content

Instantly share code, notes, and snippets.

@janbiasi
Last active August 29, 2015 14:03
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 janbiasi/bc3e51191a555b7f4469 to your computer and use it in GitHub Desktop.
Save janbiasi/bc3e51191a555b7f4469 to your computer and use it in GitHub Desktop.
Add target _blank to all links
// All links pure JS solution
var anchors = document.getElementsByTagName('a');
for (var i=0; i < anchors.length; i++) {
anchors[i].setAttribute('target', '_blank');
}
// All links w. jQuery
$('a').attr('target', '_blank');
// All outgoing links w. jQuery
$('a[href^="http://"]').not('a[href*=gusdecool]').attr('target','_blank');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment