Obfuscating Email Addresses with JavaScript (and Prototype)

I know this is probably done a million times elsewhere, but I thought this approach was pretty neat. At work, we worry about spam harvesters collecting our addresses, so we want to hide them.

So today at work, I whipped this up pretty quickly, using Google's AJAX API Library + Prototype.

<html>
<head><title>Dynamic/Obfuscated Email Link Example</title></head>
<body>
<div>
<span class="add_email_link" id="jason">This should become an email link to me!</span>
</div>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("prototype", "1.6.0.3");
    google.setOnLoadCallback( function() {
        // gather all .add_email_link's and add mailto links around their children
        $$('span.add_email_link').each( function( span ) {
            span.update( '<a href="mailto:' + span.id + '@example.com">' +
                span.innerHTML + '</a>' );
        } );
    } );
</script>
</body>
</html>

So ... guess this doesn't have anything to do w/ Perl, per se, but couldn't resist sharing. What about you? What technique do you use?

Peace,

Jason

Leave a comment

Categories

Authors

  • Dave Cross
  • Luis Motta Campos
  • Jason Purdy
  • Michael Peters
  • Steve Marvell

Recent Entries

Close