PDA

View Full Version : Hiding links from bots using javascript question



qwikad.com
03-24-2013, 03:44 AM
I need to make a link on my site undetectable for bots. I've just added rel="nofollow" to it, which should help.

I just want to make sure that bots either do not see the link or totally ignore it. I tried to find something suitable online - no such luck.

Any help will be appreciated.

djr33
03-24-2013, 03:52 AM
I need to make a link on my site undetectable for bots. I've just added rel="nofollow" to it, which should help.Good bots will listen to your suggestions, and you can give more specific instructions in robot.txt (google that if needed). That includes bots like search engines, but does not include "bad bots". They don't care what you suggest.


I just want to make sure that bots either do not see the link or totally ignore it. I tried to find something suitable online - no such luck.Javascript can't do this. It can make it harder to figure out, sort of like using emailATaddressDOTcom rather than email@address.com, but as with that, it's possible to program a bot that can figure it out. They don't usually parse Javascript, but "bad bots" might. So you may be making a lot of effort to block the bots that are already listening to your "nofollow" suggestion, while not blocking the others. I don't have any statistics on this, though.

One simple way to do this would be to change the HREF of the link using Javascript. Maybe use onload and change the HREF of an <a> tag with a certain id. Simple enough. But again, that won't stop bots from looking in the JS to figure out what's going on.

You can make it more difficult but not impossible. And you might lose some visitors along the way if it becomes hard for someone, for example, without Javascript.

qwikad.com
03-24-2013, 04:13 AM
One simple way to do this would be to change the HREF of the link using Javascript. Maybe use onload and change the HREF of an <a> tag with a certain id. Simple enough. But again, that won't stop bots from looking in the JS to figure out what's going on.


Can you make it more practical? Give me an example, so that I could build on it. Thanks!

djr33
03-24-2013, 05:31 AM
Off the top of my head, something like this:

<body onload="document.getElementById('mylink').href='http://my.new/link/';">

<a href="something" id="mylink">LINK TEXT</a>

And there are probably better ways to do this, as well as the fact that you really need to reconsider the logic behind it-- I'm not sure this is best for your site. But it's up to you.

jscheuer1
03-24-2013, 06:25 AM
If you want to confuse even the most sophisticated bot (unless it actually runs the javascript code), not to mention yourself:


<!DOCTYPE html>
<html>
<head>
<title>Obscure Links - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function Zfunction(){var z=Zfunction,r,q=(r=arguments[0]).hash[z.q.f](z.q.rr,'');q&&z.q[q]&&z.z[q]&&(function(){r[z.e.p]=[z.z[q],z.q[q],'.',z.e.a].join('');})();}Zfunction.q={who:'doc',where:'page',rr:/#/,f:'replace'};Zfunction.e={a:'html',p:'href',g:document,t:function(){var l=Zfunction.e.g[Zfunction.e.w],ll=l.length;while(--ll>-1)Zfunction(l[ll]);},w:'links'};Zfunction.z={where:'some',who:'another'};
</script>
</head>
<body>
<a href="#where">Some Page</a><br>
<a href="#who">Another Doc</a>
<script type="text/javascript">
Zfunction.e.t();
</script>
</body>
</html>

Click Here for a Demo (http://home.comcast.net/~jscheuer1/side/tidbits/obscurelinks.htm).

qwikad.com
03-24-2013, 01:57 PM
John, I need something that people will still be able to click on. It's the bots that I am trying to deceive.

jscheuer1
03-24-2013, 02:27 PM
That's what that is. I did say it would confuse you though, but it does work if javascript is enabled, and there's a script at the end you might have missed. Did you try the demo:

http://home.comcast.net/~jscheuer1/side/tidbits/obscurelinks.htm

The trick is the hash href. That becomes the key in:


Zfunction.z={where:'some',who:'another'}

and:


Zfunction.q={who:'doc',where:'page',rr:/#/,f:'replace'}

The extension is 'html' for both (gotten from Zfunction.e.a), but that can be changed if need be, even gotten via the key from Zfunction.e if the extensions are different. So a hash of "#who" becomes a link of "anotherdoc.html". Also, an extension is assumed. A hard coded . character is inserted between the filename and the extension. But that could also be changed if a folder or domain needs to be navigated to.

qwikad.com
03-24-2013, 04:36 PM
John, now I get it... and yes it is very confusing :) I will have to remove the html and the . other than that it should work.

qwikad.com
03-24-2013, 07:23 PM
John, I've just added it to my site. It's doing what it's supposed to do.

Did you design this code? It's genius.

jscheuer1
03-24-2013, 08:55 PM
Yes, I just figured, "What would be the most confusing thing I could think of, something where the actual URL never appears and variables are not descriptive of what they do?"

That's what I came up with. It's partly inspired by javascript compression methods like pack, that and my love of using objects for lookups.

BTW, if you have an actual hash tag link on the page, it should still work normally as long as its value/name doesn't appear as a key in both the Zfunction.z and Zfunction.q objects.

Oh, and you can make it even more obscure by making the scripts external.

qwikad.com
03-25-2013, 02:18 AM
Oh, and you can make it even more obscure by making the scripts external.

Now that you mentioned it, I may. Right now I have it in the page. How important (or not) that
<script type="text/javascript">
Zfunction.e.t();
</script> goes after the html tags? Can I throw everything into the external file and just keep the html tags on the page?

jscheuer1
03-25-2013, 03:07 AM
That must be after the last link on the page that needs this transformation. Easiest way to be sure is to have it just before the closing </body> tag.

You can put it all (including the Zfunction.e.t(); call which would now go at the very end) in an external file. Using a text only editor like NotePad, save it as - say, zfunction.js:


function Zfunction(){var z=Zfunction,r,q=(r=arguments[0]).hash[z.q.f](z.q.rr,'');q&&z.q[q]&&z.z[q]&&(function(){r[z.e.p]=[z.z[q],z.q[q],'.',z.e.a].join('');})();}Zfunction.q={who:'doc',where:'page',rr:/#/,f:'replace'};Zfunction.e={a:'html',p:'href',g:document,t:function(){var l=Zfunction.e.g[Zfunction.e.w],ll=l.length;while(--ll>-1)Zfunction(l[ll]);},w:'links'};Zfunction.z={where:'some',who:'another'};Zfunction.e.t();

Then on the page(s) that use it put this external script tag right before the closing </body> tag:


<script src="zfunction.js" type="text/javascript"></script>