Skip to content

Instantly share code, notes, and snippets.

@helart
Created May 4, 2021 03:41
Show Gist options
  • Save helart/99bbd9702b5d15069c620a3f54a60747 to your computer and use it in GitHub Desktop.
Save helart/99bbd9702b5d15069c620a3f54a60747 to your computer and use it in GitHub Desktop.
target-blank
<a href="document.html" rel="ext">в новое окно</a><br />
<script>
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i < anchors.length; i++) {
if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "ext") {
anchors[i].target = "_blank";
}
}
}
window.onload = externalLinks;
</script>
<a href="link" onclick="this.target='_blank'">способ 2</a><br />
<a href="link" onclick="return !window.open(this.href)">способ 3</a><br />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment