Last active
March 19, 2021 16:11
-
-
Save murgatroydj/7654015 to your computer and use it in GitHub Desktop.
Jquery snippet to add target="_blank" to all external links in a documen and force PDFs to open in a new window/tab as well.Replace mydomainname with yours to skip internal 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
$(document).ready(function(){ | |
// external links to new window | |
$('a[href^="http://"]').not('a[href*="mydomainname"]').attr('target','_blank'); | |
// force PDF Files to open in new window | |
$('a[href$=".pdf"]').attr('target', '_blank'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Thanks for gist. A small correction: mydomainname must be in quotes, like:
not('a[href*="mydomainname"]')