Last active
August 29, 2015 14:17
-
-
Save besimhu/e705cfee41d79d820e7b to your computer and use it in GitHub Desktop.
Open all external links in a new window.
This file contains hidden or 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
// Open all external links in new window. | |
$('a').each( function (i, link) { | |
var $link = $(link), | |
href = $link.attr('href'); | |
if (!!href) { | |
href = href.toString(); | |
if (-1 === href.indexOf(window.location.host) || -1 !== href.indexOf('.pdf')) | |
$link.attr('target', '_blank'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment