Skip to content

Instantly share code, notes, and snippets.

@bookchiq
Last active August 29, 2015 14:06
Show Gist options
  • Save bookchiq/6c34df808b4930cc7b65 to your computer and use it in GitHub Desktop.
Save bookchiq/6c34df808b4930cc7b65 to your computer and use it in GitHub Desktop.
Make external links open in new browser window/tab (from http://css-tricks.com/snippets/jquery/open-external-links-in-new-window/ )
/***** Make external links open in new browser 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' );
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment