The Coding Pad

Programming blog, discussions, tutorials, resources





Subscribe to get updates via email:

Delivered by FeedBurner

Spamproof your email link with Javascript

Posted in September 11th, 2007
Published in Javascript

Wouldn’t it be nice to post your email address right on your page without having to worry about spam harvesters and other malicious bots?

I do! See an example in the footer section of my Web Development Forums.

I use Javascript to do this. It is a highly effective method for a few reasons:

  1. Javascript output is unsearchable by search engines.
  2. Spam harvesters, and most other bots and spiders ignore javascript to avoid being caught in loops and infinite content generators

Here’s how to do it!

Copy and paste the script below into the HTML content of your webpage right where you want the email link to be.

Next, update the actual email information (change the variable values).
admin = you, hypertextfever = yourdomain, com = your tld (com, net, org, etc.))

Next, I recommend changing the variable names. They are currently female names that start with “s”. This is simply preference. It’s just best to diversify these variable names so that bots don’t get “wise” to it.

A good example would be to change the three instances of “susan” to “charlie”, and “sally” to “chuck”, etc. Please be aware that there are three instances of each.

<script type=”text/javascript”>
var susan = “admin”;
var sally = “@”;
var sandra = “hypertextfever”;
var sarah = “.”;
var sonia = “com”;
document.write(’<a href=”mailto:’+susan+sally+sandra+sarah+sonia+’”>’+susan+sally+sandra+sarah+sonia+’</a>’);
</script>

Easier than an email form, and it’s more usable too!





Related Posts

2 Users Commented In " Spamproof your email link with Javascript "

Subscribes to this post Comment RSS or TrackBack URL
mary says,
9-11-2007 at 16:12:33 from 68.81.98.179    

Thanks for this post Bo.

This looks like a neat trick to keep out the spam bots. I don’t always like to use contact forms since they seem so impersonal, but every time I put an email address on a website I get tons of spam, so this is a great solution to try out.

Kris says,
9-18-2007 at 11:53:35 from 198.245.165.200    

Just tried this. Will be interesting to see if I get any spam.

Leave Your Reply Below

 Username

 Email Address

 Website

Sticky note: Please double check your comments before submit Please Note: The comment moderation maybe active so there is no need to resubmit your comment
 

 Subscribe in a reader

About The Site

It is what it is, my coding pad, a programming blog, yet another place for my restless mind.