I have the following (jquery) selector looking for external links.
This works, and ignores all links that include location.hostname (e.g. www.domain.com)
My question is, how to extend this to also ignore links to subdomains of your site? (e.g. new.domain.com)
$('a').each(function() {
var href = $(this).attr('href');
if(this.hostname && this.hostname !== location.hostname)
{
$(this)
.removeAttr('target')
.attr('rel', 'external')
.attr('title', href)
.click(function() {
window.open($(this).attr('href'));
return false;
});
}
});
$('a').filter(function() {
return this.hostname && this.hostname !== location.hostname && this.hostname.indexOf('.'+location.hostname)!=-1
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With