Joe Maller:JavaScript: Protect your email addressReduce spam and junk email by using JavaScript to hide your address from spam-bots, a step-by-step tutorial. |
||
Spam-lists are generated by Spam-Crawlers and Spam-Bots. These computers only purpose is to constantly comb the web in search of email addresses to add to their lists. Thankfully they are in such a rush to keep up with the massive amount of web content that they ignore everything but the plain text of each site. Executing JavaScripts would be a waste of processor cycles, but that efficiency will help to protect our email. A few years ago I had the idea to break and then reassemble my email address with JavaScript to help prevent spam. I built something, it worked and I forgot about it. Then last year, my friend Dale Sorenson told me of a similar solution he had written, he uses a picture of his email address and then JavaScript to build the link. Check his contact page to see his anti-spam solution. This tutorial shows how to build a small, portable JavaScript to hide an email address to help reduce junk mail. I don't have any proof that it works, but the amount of junk mail I get has gone down since I started using this script on my site. The GoodsFor the impatient or those who don't care how this works, jump ahead to the final script. The text address this script produces will appear to be plain text. From a design point of view, this will completely blend in with whatever other text you have on the page. Readers will never know it was generated by a script. Readers are free to change the font or size to their preference, and the address could be read aloud by a machine for the visually impaired. Inserting Text with JavaScriptJavaScript's For example, The code to write an email address into a web page looks like this:
The parentheses contain the two halves of my email address. These strings
are assembled by the The Linking the addressThe First, we'll define a reusable variable
As mentioned on my JavaScript Rollover page,
variables are case sensitive, and Next, we'll use
Be careful with those single and double quote marks. No JavaScript Means No EmailSince this script completely relies upon JavaScript, users without JavaScript
or those who've disabled it will not see anything. Parts of Dale's image
solution (mentioned above) can be made to work here using a To show an image:
or a message:
I do not currently include this code on any of my pages. More than 98% of my visitors have JavaScript turned on and of the remaining 2%, most all of them have browsers capable of JavaScript and have it disabled by choice. Finishing upUsing the
I wrote a small script to generate personalized source code. Type an email address to generate a personalized JavaScript email protection script: One more thing for the paranoidIf you are still worried that the Spam-Crawlers might strip out the Variables can have information added to their existing contents, and that new content can even include the existing variable. Replace the
The first line is the email prefix, the second line tells JavaScript to add an at-mark and the email suffix. If you wanted to reverse this, since you are REALLY paranoid, you can:
Note that the second line was reversed to accommodate the change. The automated source code uses the super-paranoid option and reverses the email parts in the code. Links to other Anti-Spam sitesHere are links to sites dealing with preventing and fighting spam:
These are sites with similar JavaScript solutions: ConclusionsIt's not that much more typing than a normal link, and I'd gladly trade a few extra keystrokes now to avoid a ton of junk email later. I used to keep the text of this link in a little file on my desktop so I can quickly and easily access it whenever I need to. Since writing the script to build the code, I'm actually using my own page for the code. If this was helpful or interesting to you, please link to this site so other people can share this information too. Send me a note and let me know what you thought of this page. Joe Maller
January 2001 (revised May 2001) |
Film & VideoRecording the sound of PhotographyProjectsFinal Cut ProDesignWRITINGSite Notes Archive (weblog) Web ResourcesAbout Joe MallerPast Home Pages Etc.Search joemaller.comContact Me
|
|