Created
May 5, 2017 19:10
-
-
Save davist11/51706e067ed844728600bc174d024908 to your computer and use it in GitHub Desktop.
target external links
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
module.exports = { | |
init: function() { | |
this.setVars(); | |
this.addAttributes(); | |
}, | |
setVars: function() { | |
this.links = document.querySelectorAll('a[href^="http"]:not([href^="' + window.location.origin + '"])'); | |
}, | |
addAttributes: function() { | |
for (var i = 0, length = this.links.length; i < length; i++) { | |
var link = this.links[i]; | |
link.setAttribute('target', '_blank'); | |
link.setAttribute('rel', 'noopener noreferrer'); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment