How to protect your hardcoded e-mail address inside html with jQuery

Bots are crawling your html not only for existance of an a href=mailto:  but also an pure e-mail itself.

So wherever your snippet is generating a raw e-mail link in your code, or you put it manually - it's worth to consider using this jQuery function.


This jQuery function converts a span containing text "login at email example dot com" to
login@example.com
so it becomes blind for bots but not for humans.


This is a one of the ways protecting your inbox from receiving a huge amount of SPAM.

Put this snippet inside a inluded jQuery script (i.e. custon.js) via

<script src="js/custom.js">{/script>

or put this near closing the html body

$(document).ready(function($) {
_PASTE_CODE_HERE_
});

snippet:

// mailme
$('span.mailme').each(function() {
var spt = $(this);
var at = / at /;
var dot = / dot /g;
var addr = $(spt).text().replace(at,"@").replace(dot,".");

$(spt).after('' addr '" title="Send a message!" class="amail">' addr '{/a>')
.hover(function(){window.status="Send a message!";}, function(){window.status="";});
$(spt).remove();
});
// mailme END
and the html container:
<span class="mailme">login at example dot com{/span>

Of course you have to make sure you are including jQuery also.
i.e.:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">{/script>

One disadventage: Where there is a huge page to load, in the begining there could be a glipse when a visitor actually is seeing

"login at example dot com" before the jQuery function executes. This can be simply fix by hiding it in CSS for default:

 
.mailme {visibility:hidden;}

and adding

 
$(spt).css('visibility', 'visible');

in newline right after

$(spt).remove();

so this part becomes

 
$(spt).remove();
$(spt).css('visibility', 'visible');

voila!