tags:

views:

2791

answers:

7

Is there a way to use JQuery to cloak or encrypt email addresses on an HTML page without changing the syntax in the HREF?

+5  A: 

Well, just as a comment, you probably want the source to have a cloaked email address and then use jQuery to fix or construct the link to have the correct address... because bots will be looking at the source, not the results of running your javascript ;-)

Mike Stone
+1  A: 

Using JQuery may not be the route you want to take since this would be on the client side... Is there a reason you're not encrypting on server side?

Ryan Lanciaux
Correct - using JQuery to encrypt the email address will be useless, seeing as any Bot scrapping your HTML will not be running the JQuery.
samjudson
A: 

Semantic nazis would say "encoding", not "encrypting". Encrypting implies a secret is required to decode. Converting to HTML entity syntax would be a decent encoding process to keep out prying humans, but bots could easily decode it.

spoulson
A: 

To kind of piggy-back on what Mike Stone was suggesting, what I would do is encrypt it on the server-side and have something on the server-side that will decrypt it and return it back as JSON (jsonresult in mvc framework, web service, http handler, whatever). That way you could use jQuery to de-obfuscate the e-mail addresses when you wanted but it would still confuse any bot that doesn't support java script. Again this is not a bullet proof solution but it may do what you're looking for.

Ryan Lanciaux
A: 

I don't have any control over the HTML being generated, thus no server side solution is available.

mmcglynn
A: 

What I've done is obfuscate it when it's rendered and hide it, then use javascript to fix the obfuscation and show the link.

For example, you can render this from the server:

Email me

then using Javascript you can use regex to swap ^^ for @ and $$ for .

Whatever scheme you can come up with will probably be fine. Of course if the bot understands javascript then it doesn't matter anyway.

You'll block 95% of the bots that come your way and the rest of your users will see the address just fine.

Ben Scheirman
A: 

Whatever scheme you can come up with will probably be fine. Of course if the bot understands javascript then it doesn't matter anyway.

If you trigger the de-obfuscation on click and/or mouseover, rather than on document ready, you increase your stealthiness.

dansays