Skip to content

Instantly share code, notes, and snippets.

@jonathanagosto
Created December 5, 2016 18:32
Show Gist options
  • Save jonathanagosto/4c1c4403e3b584e2c993988cb907d9ca to your computer and use it in GitHub Desktop.
Save jonathanagosto/4c1c4403e3b584e2c993988cb907d9ca 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);
});
@jasonco-dev
Copy link

jasonco-dev commented Dec 5, 2016

I implemented a different workaround to modify exactly the link (a) tags inserted by DFP when the onRenderedEvent is called by each ad unit. Good stuff nonetheless, thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment