Skip to content

Instantly share code, notes, and snippets.

@davidchase
Created March 4, 2013 19:46
Show Gist options
  • Save davidchase/5084940 to your computer and use it in GitHub Desktop.
Save davidchase/5084940 to your computer and use it in GitHub Desktop.
jQuery open all external links in a new window
$("a").filter(function () {
return this.hostname && this.hostname.replace(/^www\./, '') !== location.hostname.replace(/^www\./, '');
}).each(function () {
$(this).attr({
target: "_blank",
title: "Visit " + this.href + " (click to open in a new window)"
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment