Skip to content

Instantly share code, notes, and snippets.

@cougrimes
Last active August 29, 2015 14:13
Show Gist options
  • Save cougrimes/94150b5e67a5a91bc7c2 to your computer and use it in GitHub Desktop.
Save cougrimes/94150b5e67a5a91bc7c2 to your computer and use it in GitHub Desktop.
Force all links that are not localhost to have a blank target
$(document).ready(function () {
$.expr[':'].external = function (obj) {
return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname) && !obj.href.match(/^javascript\:/) && !obj.href.match(/^$/)
};
$('a:external').attr('target', '_blank');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment