Created
November 28, 2013 17:30
-
-
Save tcelestino/7695540 to your computer and use it in GitHub Desktop.
open all links in page with target="_blank" in a new window
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
window.onload = function() { | |
var links = document.getElementsByTagName('a'), len = links.length; | |
for(var i = 0; i < len; i++) { | |
links[i].addEventListener('click', function(event) { | |
if (this.target === '_blank') { | |
window.open(this.url, '_blank'); | |
} | |
event.preventDefault(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment