Skip to content

Instantly share code, notes, and snippets.

@ryan-ethode
Created January 12, 2017 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-ethode/678931b22605f926f908ee84c4ee9aff to your computer and use it in GitHub Desktop.
Save ryan-ethode/678931b22605f926f908ee84c4ee9aff to your computer and use it in GitHub Desktop.
Automatically open all external website links in a new tab.
$( document ).ready(function() {
$(".container a").each(function() {
var pageUrl = $(this).attr("href");
if(pageUrl == null) {
var pageUrl = "nothing";
}
if(pageUrl.indexOf("://") > 0 && pageUrl.indexOf("yourdomain.com") < 0) {
$(this).attr("target","_blank");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment