Wesley's random comments about the world and the people and stuff in it.

Tuesday, January 29, 2008

How to spam proof your email links with javascript.

If you post a link to your email on your website using the classic HTML tag mailto:me@domain.com then you are almost sure to get your self added to spam list.

Spammers use software robots (bots) called harvesters that go through search engines, find websites, then scour the sites looking for the mailto tag - then they take the email out and add it to their spam mailing list.

There is an easy way to avoid this problem.

How to create a Javascript email link.

You can copy and paste this code, just change the vars name and domain in the quotes - it will create a regular looking email link on your site and cannot be read by harvestor bots.

The code here shows how to make a link for the email address me@mysite.com
with the text "email me" as the link:

<script language="JavaScript">
<!--

// change these values to match your email address

var domain = "mysite";
var name = "me";
var extension = ".com";

var link = "email me";

// do NOT change anything below this line!

document.write('<a href="mailto:' + name + '@' + domain + extension +' ">');


document.write(link + '</a>');
// -->
</script>

Note: make sure you dont put your email in the link var! if you want to use your email use the HTML code for the @ symbol which is & #64; (no spaces) so you owuld write it as
me&# 64;mysite.com which will appear on the page as me@mysite.com



2 comments:

FredC said...

I have used this trick on several websites. I also like the way described on this page.
http://blogmag.net/blog/read/39/Email_obfuscation

HomeCareQuote said...

you rock, thx wesley!

Twitter / vexcom

LeadFeed