SiteForce HomepageWeb Design and Hosting PackagesWeb Design TemplatesWeb Design PortfolioContact SiteForce

Hide your “mailto:” Email Addresses from Spambots with JavaScript

Posted by Erik M. Cunningham - September 15, 2006

Erik M. Cunningham

Ever wonder why you get so many junk emails at your business email addresses? Your web site may hold the answer. If you or your clients use “mailto:” links instead of email forms for correspondence on your web sites, your email addresses are likely to be picked up by spambots. And as we’ve all learned, once you’re on the list, it’s impossible to get off it.

Rather than pay for an anti-spam service like Spam Arrest or rely on email spam filters on your mail server, why not use JavaScript to hide your email address from spambots? Here’s how:

Place the following code in the HEAD of your HTML document:

<SCRIPT language="JavaScript" TYPE="text/javascript">
function email(department,title){
var recipient = department;
var domain = "YOURDOMAIN";
document.write('<a href=\"mailto:' + recipient + '@' + domain + '\">');
document.write(title + '<' + '/a>');
}
</SCRIPT>

Replace “YOURDOMAIN” in the code above with the domain name of your email address (eg. “siteforce.com”).

Now paste this code in the BODY of your HTML where you would like your email link to appear:

<SCRIPT language="JavaScript">email('YOURADDRESS', 'LINKTEXT');</SCRIPT>

Replace “YOURADDRESS” with your email address (eg. “ecunning”) and replace “LINKTEXT” with the text you would like to appear in your mailto: link (eg. “email us”).

That’s it! To the user, the email link functions exactly the same way as your standard “mailto:” link but your email address is invisible to most spambots.

If you want to be extra tricky, take the code you placed in the HEAD of your document and store it in a .js file to reduce the amount of code in your HTML page and make your email addresses even harder for spambots to find.

Enjoy!

15 September 2006 | JavaScript Tutorials, Intermediate JavaScript | Comments

One Response to “Hide your “mailto:” Email Addresses from Spambots with JavaScript”

  1. 1 mesapilot 20 September 2006 @ 1:58 pm

    This is a great piece of Javascript. I cannot believe how helpful this blog is. I am going to come back here every day to get invaluable information on Web Design.

    Thank you so much for saving me from the evil hordes of SpamBots!!

Leave a Reply

You must be logged in to post a comment.

Navigation

Archives

Meta

September 2006
S M T W T F S
« Aug   Oct »
 12
3456789
10111213141516
17181920212223
24252627282930


Add to My Yahoo!

Add to Google

Add to Windows Live

Subscribe in NewsGator Online

Add to Netvibes

Subscribe with Bloglines

Add to My MSN

Add to My AOL


Top Web Design Blogs

Blogroll