Created
June 15, 2015 22:01
-
-
Save jaredkc/41d8839772cde6665921 to your computer and use it in GitHub Desktop.
Open all external links in a 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
(function($) { | |
$(document).ready(function() { | |
/** | |
* Open all external links in a new window/tab | |
*/ | |
$('a').each(function() { | |
var a = new RegExp('/' + window.location.host + '/'); | |
if(!a.test(this.href)) { | |
$(this).click(function(event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
window.open(this.href, '_blank'); | |
}); | |
} | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment