Created
March 4, 2013 19:46
-
-
Save davidchase/5084940 to your computer and use it in GitHub Desktop.
jQuery open all external links in a new window
This file contains hidden or 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
$("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