-
Obfuscating Email Addresses
Off the top of my head… String substitution would be a very simple and effective way:
var obfuscated_email = "you-nospam@nospam-example.com" var email = obfuscated_email.replace(/\-?nospam\-?/g, '');
Will return you@example.com. This has the advantage of being accessible to screen reader if you implement by updating a DOM node. If Javascript is turned off, “no-spam” interpolated into an email address is still parseable for a savvy internet user while flummoxing a bot!
Today I had a client request that all email addresses displayed on their website be jumbled/encrypted/scrambled in some way to prevent them from being harvested for spam lists. Not something I am asked to do often, but I do share their concern.
There are a number of ways to do it, and I wanted to talk about my approach, which was fairly quick and dirty. You could convert all the addresses to images, or piece it together with CSS, or discombobulate it with a script or something, but I didn’t want to spend too much time on this sucker. After all, I need to have time left over to blog about it, don’t I?
Anyway, here’s what I did:
<script type="text/javascript"> var name = 'user_name'; var at = '@'; var domain = 'thedomain.com'; document.write(name + at + domain); </script>Which produces user_name@thedomain.com on the page, but the underlying text is still complex enough that crawlers probably can’t parse it well. One bummer is that you can’t click it, but that ability is less important than their request to obfuscate the addresses, I think.
What’s your take? Do you like this approach or have you used a better one successfully?
Thu04Feb