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?
why don’t you just use this :
$(“[href=’http’]:not([href='”+location.hostname+”‘])”).attr(“target”,”_blank”);
This will fail if you have a link like this:
Any solution to include such links as well?
just add a class to your link and use the :not()
add a class to you link and use the :not()
LuK, why don’t you add both statements together (http and https), comma separated? I tried it, works beautifully.
I use this :
and I never use absolute url to target internal link