Web Designing Tutorials

How To Make All External Links No-follow Using JavaScript

Pinterest LinkedIn Tumblr
Creating a webpage with proper uses of internal and external links is the oldest and most used way of Search Engine Optimization(SEO). You can make all external links no-follow using JavaScript, which tells the search engine and crawlers not to follow and crawl your hyperlinks and without using the “no-follow” tag, which allows the search engine crawlers to follow and crawl your hyperlinks.

The rel=”nofollow” attribute helps to control the flow of page rank from one website to another and maintain the pagerank of your website. You can create a link with rel=”nofollow” attribute as the following.

<a href="https://www.google.com" rel="nofollow">My Link</a>

In this post, I am going to describe different ways to make all external links no-follow using simple JavaScript code and Jquery plugin which helps to prevent following SEO juice form your website to the external links.

You May Also Like:

Making All External Links Nofollow Using Simple JavaScript Code

You can make all of your external links with nofollow tag using the following simple JavaScript code. It adds  rel=”nofollow” attribute along with target attribute to “_blank” and title attribute to “Click to open in new window” on <a href=”#”>Link</a> tag of all of the external links of your website

<script type='text/javascript'>
function myFunction() {
var x = document.getElementsByTagName("a");
var i;
for (i = 0; i < x.length; i++) {
if (location.hostname!=x[i].hostname){
x[i].rel = "nofollow";
x[i].target = "_blank";
x[i].title = "Click to open in new window";
}}}
mft=setTimeout("myFunction()",0);
function LoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function'){
window.onload = func;
}
else{
window.onload = function()
{
if(oldonload)
{oldonload();}
func();}}}
LoadEvent(function(){
myFunction();
});
</script>

Making All External Links Nofollow Using jQuery

You can also make all external links no-follow using the following jQuery code. This code also adds  rel=”nofollow” attribute along with target attribute to “_blank” and title attribute to “Click to open in new window” on <a href=”#”>Link</a> tag of all of the external links of your website

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>
var a = $(this);
var href = a.attr('href');
$(document).ready(function() {
$("a[href^='http://']").each(function () {
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr('target', '_blank');
$(this).attr('title', 'Click to open in a new window');
$(this).attr('rel', 'nofollow');
}});
$("a[href^='https://']").each(function () {
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr('target', '_blank');
$(this).attr('title', 'Click to open in a new window');
$(this).attr('rel', 'nofollow');
}});});
</script>

Please follow and like us:
RSS
Follow by Email
X (Twitter)
Visit Us
Follow Me
YouTube
YouTube
LinkedIn
linkedIn | How To Make All External Links No-follow Using JavaScript
Share

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

1 Comment

  1. Many thanks for sharing a useful and guide for nofollow links…I will try to implement it, hoping it will me to save precious time to make them nofollow manually!

Write A Comment

RSS
Follow by Email
X (Twitter)
Visit Us
Follow Me
YouTube
YouTube
LinkedIn
Share