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.
No it’s just a Jquery script so you can use it widely in any website as you want.
=), 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?
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.