Hide email address from spammers with Javascript

This post is older then 6 months, which means opinions contained were mine and any technical information is most likely obsolete.
Please contact me for text I would also sign, not only acknowledge or if post got broken during one of many server upgrades. I will be most grateful.

Update: I published a new, more safe but less friendly version of this script.

Wouldn’t it be nice, if you could post your email address on your web site without worrying spammers will pick it up?

Now you can, by applying a little bit of javascript to your web page. Just import this javascript file in head of your document and call mangle() inside your onload handler. What it does, is replace elements of form

<span class="change">billg at microsoft dot com</span>

with

<a href="mailto:billg@microsoft.com">billg@microsoft.com</a>

There are few caveats to its use. You’re not allowed to use any HTML tag inside of span blocks, which have class set to change. The script also expects such blocks to have only one class definition. If change is only part of class attribute value, this script won’t work.

You are free to use script as you please and to make any changes necessary. But if you choose to replace “at” and “dot” as delimiters, pick replacements that make address easily recognizable for those who don’t use javascript.

Note: The reason why this script works is that spammers use programs which search for email like pattern in page. They don’t interpret pages using javascript interpreter, since it would make collecting addresses significantly slower and more expensive.

Update: Jay Samec let me know there’s a bug in my code, since it didn’t handle emails with multiple dots (e.g. those with subdomains). Script has been fixed now.

Update 2: Holger Rindermann pointed out another bug and provided a patch to fix it that is now a part of the script.

15 Comments »

  1. In your ‘mangle’ code you declare:
    var parent = nodes[i].parentNode;

    ‘parent’ is a defined javascript object, & should not be used as a varibale name.

    the script also seems unnecessarily complex. why not just concatinate a few strings and call it a day?

    var eaddr = “mai”+”lto:jav”+”ascript@w”+”ork.com”;

    Comment by slippery — September 24, 2005 @ 7:46 pm

  2. Right, I missed that. It works, but it’s a slippery thing to do so I changed my javascript file.

    I decided against gluing strings together because I wanted a general script that can be aplied to any page and works even if there is more than one email address. My homepage is a very simple example of that.

    Thanks for comment.

    Comment by markos — September 24, 2005 @ 7:56 pm

  3. Hi there,

    I modified your script, so that it’ll work when the email-name itself also contains at’s and dot’s (in my example: Matthew.Dotcom). Anyway it seems to work. Here’s the code:

    =0;i–) {
    if (nodes[i].className==”change”) {
    var at = / at /;
    var dot = / dot /g;
    var node = document.createElement(”a”);
    var address = nodes[i].firstChild.nodeValue;
    address = address.replace(at, “@”);
    address = address.replace(dot, “.”);

    node.setAttribute(”href”, “mailto:”+address);
    node.appendChild(document.createTextNode(address));

    var parent = nodes[i].parentNode;
    for(var j=0;j

    Contact me: Matthew dot Dotcom at hamburg dot de

    Free JavaScripts provided
    by The JavaScript Source

    Comment by Holger Rindermann — September 28, 2005 @ 8:21 pm

  4. Thank you. Linked script is now corrected.

    Comment by markos — September 28, 2005 @ 9:25 pm

  5. http://www.comicstripgenerator.com offers a unique way of hiding your email/text from spider bots (messages are hidden/encoded in pictures).

    Comment by WHAK'd — December 30, 2005 @ 12:11 pm

  6. Certainly an interesting idea. The only problem I have with it is that it’s difficult to read email address for visually impaired people.

    Comment by markos — December 30, 2005 @ 10:44 pm

  7. Why not do something with user interaction?

    function mailto()
    {
    document.getElementById(’mailto’).href = ‘mailto:jeroen@haan.net’;
    }

    jeroen ad haan dot net

    Comment by Jeroen Haan — November 13, 2006 @ 12:59 am

  8. <a id=”mailto” onmouseover=”mailto()” href=”#”>jeroen ad haan dot net</a>

    Comment by Jeroen Haan — November 13, 2006 @ 1:03 am

  9. I did. There’s a link to an updated version of the script right at the start of the post.

    Comment by markos — November 13, 2006 @ 11:43 am

  10. I am having a horrible problem with spamers, and desperately need to stop them for emailing over 500 email per day into my inboxes.

    I don’t know JavaScript at all…did I mention I know nothing. I am a self taught coder due to the inability of a new business to be able to afford an expert.

    1st. Is there a way for you to paste the code that goes into the head of the document on this page for copying. I can’t open the file extention.
    2nd. Is there a way to hightlight or bold the sections I would need to change in order to put my email addresses into the pages? (know what I’m talking about?)
    3rd. Is there a specific place within the page that I need to put certain code and if so what code?

    Comment by Edith — December 30, 2006 @ 8:34 pm

  11. A problem is that it changes the textcolor to black.
    I want white text on black background, and what ever I do, style the entire table, the cell, or the “change” class, I only briefly see the unmunged adress in white, then the munged adress is in black;unreadable until I mark (as in ’select for cut/paste) the area with the cursor.

    #10: your adress is already harvested, and you will continue to receive spam for a very long time. You should change emailadress after munging works, but then your customers probably won’t find you…

    Leif

    Comment by leif — June 21, 2007 @ 12:30 pm

  12. It shouldn’t change the color of anything. Can you please send me an example, so I can see what the problem is?

    Comment by markos — June 21, 2007 @ 10:22 pm

  13. Hi,
    I am using
    http://www.mobilefish.com/services/hideemail/hideemail.php to protect my email address against spam bots.
    This site also contains other useful tools.

    Comment by Jane — August 16, 2008 @ 4:16 pm

  14. Hello,
    there is a webpage, http://www.emailhide.org, that encrypts your email address in a secure manner. All you nedd to do is type in your email address and is returned html code with a link with your encrypted email. I’ve tried and now i use it everytime. There’s also a automatic gen for webmasters. Check it out.

    Comment by miguel — February 1, 2009 @ 1:55 pm

  15. Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

    Comment by sandrar — September 10, 2009 @ 9:23 pm

RSS feed for comments on this post. | TrackBack URI

Post a comment: