SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My user friendly anti spam email script, what do you think?

    We don't like putting our email addresses on our pages because we know we'll be spammed big time!

    Of course you could use javascript and 'document.write' it out, but who wants script tags in his body? I don't!

    So today I made the below and I thought I'd share. It kinda explains itself better then I ever could so...
    HTML Code:
    <html>
    <head>
    <title>Anti spam email script</title>
    <script src="../scriptlib/x/x_util.js" type="text/javascript"></script>
    <script type="text/javascript">
    // string spanclass : the class of the span element(s) in which the link has to be generated
    // string email : the full email address
    // string appendix : piece of text which will be appended to the link (can be omitted)
    function hiddenEmail(spanclass, email, appendix) {
        var maillink = null;
        var linktext ='';
        var child = null;
        var span = null;
        var i = 0;
        // find all the 'span' elements with a class of 'spanclass'
        // xGetElementsByClassName is part of the X library from [url]www.cross-browser.com[/url]
        for (i=0; span = xGetElementsByClassName(spanclass, document, 'SPAN')[i]; i++) {
            // if there's any text inside the span, it will be used as the linktext
            if ((child = span.firstChild) && child.nodeType == 3) {
                linktext = child.nodeValue;
                span.removeChild(child);
            // else just use the email address as the linktext
            } else {
                linktext = email;
            }
            // construct the link
            maillink = document.createElement('A');
            maillink.href = 'mailto:' + email;
            maillink.appendChild(document.createTextNode(linktext));
            // and put it in the span
            span.appendChild(maillink);
            // if there's an appendix defined, append it
            if (appendix) {
                span.appendChild(document.createTextNode(appendix));
            }
        }
    }
    
    // the setup (not to defeat the whole purpose of the script
    // this must really be done in an external file):
    function initHiddenEmail() {
        hiddenEmail('john', 'johndoe@example.com');
        hiddenEmail('john2', 'johndoe@example.com', ' or ');
        hiddenEmail('jane', 'janedoe@example.com');
        hiddenEmail('jane2', 'janedoe@example.com', ' or ');
    }
    
    </script>
    </head>
    <body onload="initHiddenEmail()">
    
    <br /><strong>Nothing in the span, so it will show the email address:</strong>
    <br />Email: <span class="john"></span>
    <br /><strong>Whatever text is inside the span becomes the linktext:</strong>
    <br /><em>Warning! Also a single space character!</em>
    <br />...my good friend <span class="john">John Doe</span> told me that...
    <br /><strong>Here we follow the span with a link to a server side message form for the users that
    have javascript disabled and we use the 'appendix' argument to link the two nicely together:</strong>
    <br />Contact: <span class="john2"></span><a href="mailbox.php">click here to send me a message</a>
    
    <br /><br /><strong>And Jane gets the same threatment:</strong>
    <br />Email: <span class="jane"></span>
    <br />...and nobody can throw an instant party like <span class="jane">Jane</span> does, we...
    <br />Contact: <span class="jane2"></span><a href="mailbox.php">click here to send me a message</a>
    </body>
    </html>
    So... do you like it? Do you see any problems with it? Please let me know!!!

    Rik
    Last edited by Zoef; Dec 22, 2003 at 19:45.
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    The only problem I see is the obvious "won't work if JS is disabled" thing and the other obvious "what if I use hotmail?" thing . Why not just build a simple contact form instead, and have it email the person directly? That way you get no risk of spam and it works for everyone right then and there.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you're going to use a contact form, then this whole thread is moot

    plus, not every site owner will have the cgi capability for a contact form

    the standard way to handle the "doesn't have javascript enabled" situation is with the NOSCRIPT tag

    obviously the NOSCRIPT would not contain a contact form

    so you need to put something into the NOSCRIPT that tells people how to contact you by email

    my recommendation:

    <noscript>
    <p>Email: joe <strong>at</strong> example <em>dot</em> com</p>
    </noscript>

    i've been involved in heated discussions with web developers who feel that this is not dumbed-down enough and that there will be people who won't know what to do with that

    my feeling is that you cannot help those people (both the ones who won't know what to do with that, and those web developers)

    Rik, you got this script online anywhere?

    i've got a completely different one, in addition to a contact form -- http://rudy.ca/contact.cfm

    rudy

  4. #4
    SitePoint Zealot CatsEyeDesigns's Avatar
    Join Date
    Dec 2003
    Location
    Florida
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've heard that email address spiders can't read ascii codes, so I made a simple ASP script that converts an email address into a mailto link composed entirely of asci codes. The resulting link works fine, but I don't know if email spiders can read it or not. Anyone know anything about email spiders and whether or not the can read asci coded email addresses?

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    well i certainly cannot speak for all email harvesters, but i would be totally surprised if there wasn't some evil spider out there that includes basic ascii code evaluation

    i mean, if you were writing an evil email harvester spider, wouldn't you include ascii evaluation? you're going to visit millions of pages, why couldn't you spend a few nanoseconds looking for ascii-encoded emails?

    totally unprotected emails have been picked up by so many bots, that their owners likely now have spam filters on, whereas ascii encoded emails have probably not been picked up a lot, so your chance of actually getting through to those people is better, and therefore more of an incentive for the evil bot writers to go after

    i think nowadays the obfuscation has to be a little better than mere ascii codes

    rudy

  6. #6
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reactions !

    No I don't have it online, only wrote it yesterday. (Why, want to try to see if you can spider it it? ) It was more of an excersise in scripting. I've only very recently started to develop my javascript skills seriously.

    Yesterday I was googling some to find some more resources and tutorials and I came across the rudimentary trick (script tags and document.write it out in the middle of the html) and I thought "that can be done better".

    Yesterday I also downloaded and browsed the X library and noticed the xGetElementsByClassName function.

    So I came up with the idea of using an empty span element to render the email address dynamically. The link between the (non semantic) span element and the predetermined email simply being the classname of the span.

    And that's what I did. I foresaw some of the remarks posted here so I did try to make somewhat flexible. If you look at the examples in the html of that script you'll see 3 ways of using it:

    In the first example, the span is left empty so the script will render the email address as the link text. This obviously does not work very well when javascript is disabled.

    The second example has text in the span. Any text within the span element will automatically be rendered as the link text. This can work well 'inline', as shown in the example. With javascript disabled the text is shown as 'normal' text, in other words, it degrades gracefully.

    The third example is an attempt to get the best of both worlds. With javascript disabled, a link to a severside powered contact form is shown. With javascript enabled the email link will be rendered in front of that. In between those two links you'll also find the text ' or ', which has been set with the optional 'appendix' argument of the initialisation function. Gracefull degradation again (or so I think ). This example can work well in a contact directory kind of situation.

    Why not do away with all this and just use a contact form instead?

    Well, why not have a contact form and serv up an email address as well, for those 90% of users that do have javascript enabled?

    It's all about giving the user choice isn't it? I know I have copied and pasted email addresses (or even ...the horror! ...used a byro!) for future reference.
    Edit:

    Or maybe your user loves hotmail!


    Mmmmm... I did go on a bit, didn't I? Just thought I'd clarify a bit my thinking behind this little script, I guess I've done that now.

    One more thing I'd like to ask... How does it look from a programming point of view? Coding style, cross browser... Please give me some critique. As I said I'm still fairly new to client side scripting so I'd appreciate some feedback.

    Ok, I'll stop now.

    Thanks again!

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  7. #7
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The spam spiders today do read ASCII codes, and even boast about it in their features list.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •