One for the lazyweb: better javascript e-mail obscurifier

I’m currently using a javascript to generate my e-mail on this page in a way that spambots apparently can’t detect. Described in brief, it spits out a mailto link, with my account name, then an encoded at-sign, then my domain name. This is all hard-coded into the script (have a look).

Although I lack the coding chops to make it work just right (much less make it elegant), I’d like to generalize this to work as follows:

The script is called with two or (optionally) three parameters. The first parameter is the account name. The second is the domain name. The third is the text (or image tag) that will be used for the link text — something like “mail me”. If the third parameter is not present, the e-mail address itself is inserted as the text.

And it would be great if there were a plug-in that inserted this into Movable Type so that it automatically re-coded e-mail addresses in the main content and in comments.

4 thoughts on “One for the lazyweb: better javascript e-mail obscurifier”

  1. You might want to take it a step further by doing something like this:

    var address1 = ‘adam’;
    var address2 = ‘rice’;
    var address = address1 + address2;
    var domain1 = ‘crossroads’;
    var domain2 = ‘net’;
    var domain = domain1 + ‘.’ + domain2;

    Just a thought; it’s similar to how I do it on my blog.

  2. function spamblockmailto (domain, account, text) {
    var myat = String.fromCharCode(64); // @
    document.write(”);
    document.write(account + myat + domain);
    } else
    document.write(‘\” title=\”‘+text+’\”>’+text);
    document.write(”);
    }

    in html
    spamblockmailto(‘ukr.net’,’vitaly7913′,’my email’)

  3. Sorry, html tags %(

    =====
    13:function spamblockmailto (domain, account, text) {
    14: var myat = String.fromCharCode(64); // @
    15: document.write(‘<a href="mailto:’);
    16: document.write(account + myat + domain);
    17: if (text==null || text.length==0) {
    18: document.write(‘\">’);
    19: document.write(account + myat + domain);
    20: } else
    21: document.write(‘\" title=\"’+text+’\">’+text);
    22: document.write(‘<\/a>’);
    23:}

    ====

  4. Joe–thanks, but I want something that can be used for any e-mail address with minimal difficulty. The way I’ve been doing it seems to be sufficient to thwart spambots already, so I don’t feel the need to break it up more.

    Vitaly–that looks like it. Thanks much.

Comments are closed.