Skip to content

Instantly share code, notes, and snippets.

@blogjunkie
Created November 4, 2014 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogjunkie/f4a66c30a8d92d682609 to your computer and use it in GitHub Desktop.
Save blogjunkie/f4a66c30a8d92d682609 to your computer and use it in GitHub Desktop.
Open external links in new window with jQuery
<!-- open external links in new window -->
<script type="text/javascript">
jQuery(document).ready(function($) {
$('div.entry-content a, aside.sidebar 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');
});
}
}).addClass('externallink');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment