Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
GTM code to open external links in a new tab. Learn more at
var links = document.links;
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname && links[i].protocol != 'tel:' && links[i].protocol != 'mailto:' ) {
links[i].target = '_blank';
links[i].rel = 'noopener noreferrer';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment