Hello, can someone recommend me a javascript to post a nofollow tag on each and every outgoing link on my site? Maybe you know this one friend: @JEET Thanks
Is there a reason you need to use Javascript to do it? Here's a sample of how you could do it <HTML> <head> <style> body {font-family: arial;} a.altered {color: red;} </style> </head> <body> <ul> <li><a href='www.digitalpoint.com'>digitalpoint</a></li> <li><a href='abc.com'>abc</a></li> <li><a href='def.com'>def</a></li> </ul> </body> </html> HTML: var list = document.getElementsByTagName('a'); for (var i = 0; i < list.length; i++) { console.log(list[i].href); if (list[i].href.includes("digitalpoint.com")) { //nothing to do } else { console.log(i); list[i].classList.add("altered"); list[i].setAttribute('nofollow', 'nofollow'); } } Code (JavaScript):
The reason is the external links are generated into pages created by a plugin that do not exist in wordpress. I tried finding the place of the plugin that generates the links but couldn't find it. Is there a reason you copied html? The correct javascript is this one? var list = document.getElementsByTagName('a'); for (var i = 0; i < list.length; i++) { console.log(list.href); if (list.href.includes("digitalpoint.com")) { //nothing to do } else { console.log(i); list.classList.add("altered"); list.setAttribute('nofollow', 'nofollow'); } }
Hi For certain links on your site, you might want to tell Google your relationship with. For regular links that you expect Google to follow without any qualifications, you might remove this attribute from links posted by members or users who to by an <a> tag), except nofollow , which is also available as robots meta tag.
I added this code to my site's header and it broke: "var list = document.getElementsByTagName('a'); for (var i = 0; i < list.length; i++) { console.log(list.href); if (list.href.includes("digitalpoint.com")) { //nothing to do } else { console.log(i); list.classList.add("altered"); list.setAttribute('nofollow', 'nofollow'); } }"
what line did it break on? did you debug it, step through the code using the developers tools to see the values that variables have?
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.
These guys are just trying to get their post count up by writing random replies that is a bit related to the question
When you say "It broke", what do you mean? Did it give an error message? Did the entire Website just not open like "White screen of death"? Did the code itself give some error? Try to be specific. Also, a code like this should be put as the very bottom of the page. Remember it is querying all a tags. If you put it on the header, most of the a tags have probably not yet loaded. Or put your code here: document.addEventListener("DOMContentLoaded", function() { // Put your code here... }); Code (JavaScript):
I'll never understand when people say this, as they often do. What possible good does having a large post count do for you? Believe me when I say that nothing helps. Not a big like number, post count, best answers, trophy points, member status,...nothing. You are only as good as your last post.
Oh, it does help. It helps A LOT depending on why you are here. I invite you to read Digital Point rules and Policies etc. Do you still think it doesn't help?
I don't know about points but the post count of users gives more abilities in most forums including this one. The simplest example is you cannot post a link with < 10 post count on most forums. On some other forums like BHW, you cannot create a BST thread with < 100 post count. There are countless rules like that and DP also has some unless it was changed recently So saying high post count does no good is just NOT CORRECT
Which is HIGHLY relevant to this thread, given that nofollow on links is often done to make it so that people (or bots) who do spam pointless links get nothing out of it. #1 reason for mindless "pointless poster magnet" threads and replies is to get that sweet sweet post count up to where the ability to post links, images, PM's, or attachments become unlocked. That said, if the links are in fact being generated by JavaScript -- basically being inaccessible -- a LOT of search engines won't even recognize they exist in the first place. If you REALLY need to do this to them, you likely need to wait or hook so that any such scripting is run AFTER the one that's making them. The window LOAD event isn't going to provide that and might fire before, depending on where you place it in relation to the script making those links. Placing the script inside <head> is even WORSE in that regard, which is part of why 99.99% of the time you see <script> inside <head>, you're looking at those pesky 3i of web development. Ignorance, Incompetence, and Ineptitude. Which is really why NONE of this has ANY blasted business being done with client-side scripting. Neither these links nor setting nofollow on them. If you care at all about usability or accessibility, not a lick of this is any of JavaScript's flipping business! -- edit -- and @sarahk, it might help to use MODERN JavaScript. for (var a of document.getElementsByTagName("a")) { if (a.href.includes("digitalpoint.com")) { //nothing to do } else { a.classList.add("altered"); a.setAttribute("nofollow", "nofollow"); } } Code (markup): Kills off "variables for nothing" and the slow-ish nature of array lookups.
Oh, and just for laughs, if you absolutely positively need the fastest executing way to iterate through them. for ( let i = 0, anchors = document.getElementsByTagName('a'), a; a = anchors[i]; i++ ) { Code (markup): That's actually the best approach. On most websites you likely wouldn't have enough anchors for the speed difference to matter, but if it's something like a link farm page where you need to shave off every last possible millisecond per iteration, that's the GOAT. If raw speed doesn't matter, I'd use the for/of in my initial rewrite for clarity sake since "test on assignment" alone confuses rookies, much less using it as the test-case in a for loop. All good code is a balancing act, prioritizing what matters in the moment. Unless of course for some jacked-up whackadoodle reason you need support for older browsers that don't support for/of... which is basically IE at this point.
Not entirely true as my avatar was an angel for about a year, and also a cute koala bear for about 6 months. *Isn't it just wonderful how we all stay on topic like we do?