Code Snippet
Find all Internal Links
Find all links that start with the sites domain, a slash, relative file path, or a hashtag.
var siteURL = "http://" + top.location.host.toString();
var $internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']");
Surely this only works with wordpress though? What if I just had <a href=”about/img” rel=”nofollow”>? This wouldn’t be selected. You’d have to use this as an overwrite.
=), I use the following to find ALL EXTERNAL Links, for what kind of taks you want to find the INTERNAL LINKS?
$(window).load( function() {
$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr('target','_blank');
});
but the problem I ran into was if the external Link has a https:// then it’s not recognized…how would I fix that in the above example?