jQuery antispam mailto

23rd gen 2012jQuery, , , , , ,

As you probably already (and sadly) know, spam bots are getting relentlessly smarter and smarter at harvesting email addresses from web pages.

Actually it is so damn easy for a spam bot to pick up your e-mail address that putting some some eloquent code like this out there, is like praying the crawlers for spam:

<a href=”mailto:support@domain.com”>contact us</a>

Given that spam bots seldom if ever process javascript, is easy to tack on a simple jQuery script to deceive the most of them. Here’s how:

Just write something like this in the place of the above-mentioned eloquent code:

<div id=”emailnospam”>Please turn javascript on to contact us.</div>

And than just put this jQuery script where appropriate:

function no_spammail(user, domain, subject){ return ‘mai’ + ‘lto’ + ‘:’ + user + ‘@’ + domain + ‘?subject=’ + subject };
$(‘#emailnospam’).html(“<a href=’#'>contact us</a>”); $(‘#emailnospam’).click(function() { window.location.href = no_spammail(‘support‘, ‘domain.com‘, ‘[YOUR SUBJECT]‘); });

…et voilà!

PS: if you are feeling paranoid you can also encrypt the email address using one of the following services: http://www.jottings.com/obfuscator/ or http://www.mailtoencoder.com/ .