Created
September 1, 2015 16:27
-
-
Save cmatskas/bb1e4ee3f98dee00909a to your computer and use it in GitHub Desktop.
ghost-replace-link-target.js
This file contains hidden or 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
// the original version of this code can be found here and full disclosure - it's not mine: | |
// https://github.com/kyleshockey/ghost-external-links/blob/master/ghost-external-links.js | |
window.jQuery || document.write("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'>\x3C/script>") || console.warn("Ghost External Links was unable to detect or add jQuery to the page."); | |
$(document).ready(function() { | |
$("a[href^=http]").each(function(){ | |
var excluded = [ | |
// format for whitelist: 'google.com', 'apple.com', 'myawesomeblog.com' | |
// add your excluded domains here | |
]; | |
for(i=0; i<excluded.length; i++) { | |
if(this.href.indexOf(excluded[i]) != -1) { | |
return true; | |
} | |
} | |
if(this.href.indexOf(location.hostname) == -1) { | |
$(this).click(function() { return true; }); | |
$(this).attr({ | |
target: "_blank", | |
title: "Opens in a new window" | |
}); | |
$(this).click(); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment