Last active
August 29, 2015 14:01
-
-
Save iamgabeortiz/8d38d89e7cba8dbaad61 to your computer and use it in GitHub Desktop.
Open links external to your site in a new tab/window via jQuery.
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
// ------------------------------------------------------------------------------- | |
// Opens all external site links in a new tab/window | |
$( document ).ready(function() { | |
$("a[href^='http:']:not([href^='http://" + window.location.host + "'])" | |
|| "a[href^='https:']:not([href^='https://" + window.location.host + "'])") | |
.each(function() { | |
$(this).attr("target", "_blank"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did not come up with the original code, but was researched from several sites. Primarily this one. I am open to tweaks to optimize this code. 😃