Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kamil-adam/f7710406162aa6abd6a0a41452238659 to your computer and use it in GitHub Desktop.
Save kamil-adam/f7710406162aa6abd6a0a41452238659 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.
<script type="text/javascript">/*<![CDATA[*/
$(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');
});
/*]]>*/</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment