3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Obscure your email address from harvesters with Javascript

Obscure your email address from harvesters with Javascript
This Instructable is for those with some web development knowledge who have their own websites.

Sometimes you might want to show your email address to your visitors on your website but hesitate doing so because of the numerous bots crawling the web looking for email addresses to spam. In this Instructable, I will show you a javascript technique you can use to hide your email address from these harvesters while keeping your email address in plain view to your website visitors.

The harvesters used are smart but not perfect. What they do is crawl through the web looking for text on pages that look like an email address: characters like "blahblahblah @ something . com". Whenever they detect a dot and an at symbol in the same text, they assume it to be an email address. So typing out your email address in plain HTML is not a very good idea because one of these bots will quickly store your email address in a database and often send out spam to you.

We can use javascript to confuse the harvesters as shown in the next step.
 
Remove these adsRemove these ads by Signing Up
 

Step 1Using a program to confuse a program (the part for geeks)

Using a program to confuse a program (the part for geeks)
Non-Geeks who just want a working copy for their website should move on to the next step to avoid the intricacies of how the code actually works.

Harvesters are just programs written in a way to capture your email address on a webpage. We can write a very simple program to confuse them.

We must create a string of characters that will represent the letters and symbols in our email address. We could also use one for email addresses that incorporate numbers and other symbols, but for simplicity of this tutorial I will only be showing you one for very basic email addresses that have only letters:
var chars="@abcdefghijklmnopqrstuvwxyz."; // for very simple email addresses that contain only letters

Next we create a variable that will hold our actual email address that we want to output to the webpage:
var email = "peter"+chars[23]+"schlamp"+chars[0]+"gmail"+chars[27]+"com";

Every string in javascript is also an array. So if I wanted to grab a single character from my chars variable above, I could do so by referencing the index of my chars array like so chars[1], which is associated to "a". Because javascript array indexes start at the number 0, if I reference chars[0], I will get back the character "@" from the chars array. I set my chars array above in a way that if I want to reference the 1st letter of the alphabet, "a", I would call chars[1], and if I want to reference the 26th letter, "z", I would call chars[26]. So, the email variable (above) references my entire email address by chaining together real strings like "peter" and calls to my chars array.

alert(email);  // outputs my email address in an alert box

The next step will show all the code together and a way to output it on your page.
« Previous StepDownload PDFView All StepsNext Step »
1 comment
Mar 15, 2011. 11:51 AMseerixprojex says:
Sweet. Much better than the method I was using. Thanks!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
2
Followers
3
Author:peter_schlamp(PeterSchlamp.com)