Created
January 12, 2017 20:35
-
-
Save ryan-ethode/678931b22605f926f908ee84c4ee9aff to your computer and use it in GitHub Desktop.
Automatically open all external website links in a new tab.
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() { | |
$(".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