Skip to content

Instantly share code, notes, and snippets.

@nurumayuapp
Created May 24, 2019 13:42
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 nurumayuapp/ff2bb5bf50624d4397cda76e43b5f47f to your computer and use it in GitHub Desktop.
Save nurumayuapp/ff2bb5bf50624d4397cda76e43b5f47f to your computer and use it in GitHub Desktop.
Anchor tag automatic targeting
<script>
var anchors = document.getElementsByTagName('a');
for(var i = 0; i < anchors.length; i++) {
var a = anchors[i];
if (!a.href.length || ~a.href.indexOf(location.host)) { continue }
a.target = '_blank';
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment