Skip to content

Instantly share code, notes, and snippets.

@melchoy
Created January 2, 2010 03:20
Show Gist options
  • Save melchoy/267366 to your computer and use it in GitHub Desktop.
Save melchoy/267366 to your computer and use it in GitHub Desktop.
handleExternalLinks
handleExternalLinks: function() {
var hostName = window.location.hostname;
var links = document.getElementsByTagName("a");
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf(hostName) == -1) {
var curTitle = (links[i].getAttribute("title")) ? links[i].getAttribute("title") + " - ": "";
links[i].setAttribute("target", "_blank");
links[i].setAttribute("title", curTitle + "opens in new window");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment