Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jasonco-dev/dbb9f1edf1775b8bd9c547567c08d985 to your computer and use it in GitHub Desktop.
Save jasonco-dev/dbb9f1edf1775b8bd9c547567c08d985 to your computer and use it in GitHub Desktop.
Find all tags using target="_blank" and inject rel="noreferrer noopener"
var aTags = document.querySelectorAll('[target]');
var att = document.createAttribute('rel');
att.value = 'noopener noreferrer';
aTags.forEach(function (tag) {
var nodeClone = att.cloneNode(true);
tag.setAttributeNode(nodeClone);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment