Created
January 9, 2016 20:34
-
-
Save dboutote/6a357965f95ea70913df to your computer and use it in GitHub Desktop.
jQuery script to add target=“_blank” for outgoing links
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( $ ) { | |
$('a[href^="http://"]').filter(function(){ | |
// filter out links that have the same domain name as the current page | |
return this.hostname && this.hostname !== location.hostname; | |
}) | |
// add a CSS class of "external" to each external link (for styling) | |
.addClass("external") | |
// inform visitor that link will open in new window | |
.attr({ | |
target: "_blank", | |
title: function(){ return this.title + ' - Link will open in new window' }, | |
}); | |
} )( jQuery ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment