Last active
December 16, 2015 17:08
-
-
Save imagehat/5467788 to your computer and use it in GitHub Desktop.
Open external links and PDFs in a new window
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
// Open external links and PDFs in a new window | |
$("a[href^='http'], a[href$='.pdf']").each(function() { | |
if(this.href.indexOf(location.hostname.replace(/www./gi, "")) == -1 || this.href.lastIndexOf('.pdf') !== -1) { | |
// Ensure subdomains are not counted as external | |
if(this.href.indexOf('mywebsite.com') == -1) { | |
$(this).click(function() { | |
window.open(this.href, "_blank"); | |
return false; | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment