Created
August 23, 2013 20:53
-
-
Save ubermichael/6323890 to your computer and use it in GitHub Desktop.
Open all external links in a new window/tab. Scan all the links in an HTML document, and add target="_blank" to any that go to a different domain.
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
$(function(){ | |
var hostname = window.location.hostname.replace('www.', ''); | |
$('a').each(function(){ | |
var link_host = $(this).attr('hostname').replace('www.', ''); | |
if(link_host !== hostname) { | |
$(this).attr('target', '_blank'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment