Tuesday, October 20, 2009

Protect your email address from spam bots using jQuery

It is very useful to leave email address for your site visitors but damn spam bots finds them, and we get only not useful spam emails. But there is good way to protect your email address from spam bots using jQuery.

First step where you want to display your email add with class "myemail" (you can change this) like this:







Now in html head, add script witch would append this span with your email address, witch is exploded in your javascript variables:


$(function(){
var _em_o = 'my';
var _em_t = 'sec';
var _em_th = 'ret';
var _em_f = '@';
var _em_fi = 'ema';
var _em_s = 'il.';
var _em_se = 'com';
var anchor = $('');
anchor.attr('href', 'ma'+'il'+'to:'+_em_o+_em_t+_em_th+_em_f+_em_fi+_em_s+_em_se);
anchor.text(_em_o+_em_t+_em_th+_em_f+_em_fi+_em_s+_em_se);
$('.myemail').append(anchor);
});


In additional you can use some kind of encoding to completely hide your email from damn spam bots.

No comments:

Post a Comment