javascript - How can I add rel="follow" to specific domains manually when setting all external links with rel="nofollow"? -
i'm building community social network or whatever call. set code external links become not followed links.
now, want code allows me remove nofollow att specific domains , add follow att, i've option add quality domains manually in .php affect root folders , sub-domains under these specific domains.
the main point not treat domains spam or not recommended search engines, instead want recommend , quality domains used user in community search engines.
the project: http://www.jumzler.com/
a full sulation, resources, or headlines do.
thank you.
ive set client side script using jquery think meets requirements requested.
$.setallowexternallinksfollowed = function(externallinkwhitelistarray) { "use strict"; var $externaldomlinks = $('a[href^="http"]'); $externaldomlinks.each(function() { var $linkinstance = $(this); // nofollow ext links $linkinstance.attr('rel', 'nofollow'); externallinkwhitelistarray.foreach(function(whitelisteduri) { if ($linkinstance.attr('href') === whitelisteduri) { // rid of rel=nofollow whitelisted links $linkinstance.attr('rel', ''); } }); }); };
which initialized in views needed so:
"use strict" $.setallowexternallinksfollowed([ 'http://www.google.com', 'http://www.cnn.com' ]);
all other external links have rel="nofollow" in dom inspector once script has chance parse , manip dom. whitelisted uri's instead have attribute rel="nofollow" truncated rel="" (or whatever see fit project minor adjustment).
see in action pen: http://codepen.io/nicholasabrams/pen/qdxwxb
i hope fits bill!
ps: if on server side, must in area of backend code links generated, , similar comparison appears in jquery solution offered. without seeing backend code renders/generates links not feasible replicate solution serverside (do links come array, or static? have no way of doing on server if links static - know based on op.
Comments
Post a Comment