Created
April 12, 2012 18:53
-
-
Save dfadler/2370055 to your computer and use it in GitHub Desktop.
Opens external links in new window
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
// If the link being clicked is external its opened in a new window | |
// http://css-tricks.com/snippets/jquery/open-external-links-in-new-window | |
$('a') | |
.bind('click', function(event) { | |
var a = new RegExp('/' + window.location.host + '/'); | |
if(!a.test(this.href)) { | |
event.preventDefault(); | |
window.open(this.href, '_blank'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment