Created
December 5, 2016 18:32
-
-
Save jonathanagosto/4c1c4403e3b584e2c993988cb907d9ca to your computer and use it in GitHub Desktop.
Find all tags using target="_blank" and inject rel="noreferrer noopener"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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.