Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxlipsky/bc95db6217a8d2285eee39d2359ff9e6 to your computer and use it in GitHub Desktop.
Save maxlipsky/bc95db6217a8d2285eee39d2359ff9e6 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