Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Created November 28, 2013 17:30
Show Gist options
  • Save tcelestino/7695540 to your computer and use it in GitHub Desktop.
Save tcelestino/7695540 to your computer and use it in GitHub Desktop.
open all links in page with target="_blank" in a new window
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