How to Mask an Email Address

by Contributor

Spammers can be a real nuisance, especially you want to display your email address on your site so visitors can contact you by email. Many spammers use email harvesters to build their databases. These programs visit websites in order to compile lists to which the spammer sends junk email. By taking a few simple steps using Javascript, you can hide an email address from harvesters while still making it visible to legitimate contacts.

Create a sub-folder of your main site root and name it "js." You'll store Javascript files in this sub-folder so you can easily find them later.

Open WordPad, Notepad, an HTML editor or some other text editor and open a new blank document. Be sure you don't use Microsoft Word, it doesn't work too well with web programming languages.

Add this block of code to your document:

Delete "yourname" and replace it with the user name for your email address. If your email address were john@abc123.com, then you'd replace "yourname" with "john."

Replace "yoursite" with the domain for your email address. Using our example, john@abc123.com, you would delete "yoursite" and replace it with "abc123.com."

Save the file in your Javascript folder as "mailto.js."

Open the HTML file where you want to place your email link and paste this line in an appropriate place:

Need to Contact Us?

You can amend "Need to Contact Us?" to read anything you desire.