Last active
April 21, 2018 09:17
-
-
Save janzikmund/d6d6053d077bcb80d631 to your computer and use it in GitHub Desktop.
Automatically open external link to new window using target="_blank"
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
// extend jquery by external links selector | |
jQuery.extend( jQuery.expr[':'], { | |
external: function(obj) { | |
return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname) && !obj.href.match(/^javascript\:/) && !obj.href.match(/^$/); | |
} | |
}); | |
jQuery(document).ready(function() { | |
// automatically open external links to new window | |
jQuery('a:external').attr('target', '_blank'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment