Created
February 6, 2015 15:26
-
-
Save rbk/cdb21744958bbbeba38e to your computer and use it in GitHub Desktop.
Make links to other domains open in a new tab( requires jQuery)
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 offSiteLinks() { | |
var all_links = $('a'); | |
all_links.each(function(){ | |
var link = $(this).attr('href'); | |
var tld = 'com'; | |
if( link != null ){ | |
if( link.match( /\.pdf{1}$/ ) || ! link.match( '/' + location.hostname + '/' ) && ! link.match( /#/ ) && ! link.match(/mailto/) ){ | |
$(this).attr('target', '_blank'); | |
} | |
if( link.match('/' + location.hostname.replace(tld, 'org') + '/') ) { | |
$(this).attr('target'); | |
} | |
if( link.match(/newson6/) ){ | |
$(this).removeAttr('target'); | |
} | |
if( link.match(/tel/) ){ | |
$(this).removeAttr('target'); | |
} | |
} | |
}); // end pdfs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment