- JQuery Tutorials – Use JQuery to protect/rewrite emails from spam bots
- jQuery Tutorials – Hide/protect mailto: links from spam bots and email harvesters #2
- jQuery Tutorials – Hide/protect mailto: links from spam bots and email harvesters #3
Here is a jQuery snippet that can protect email addresses from email harvesters.
All you need to do is to inlcude .mail class to your “mailto:” html links like the example below.
1 |
<a href="mailto:peter_[at]_example.com"> peter_[at]_example.com </a> |
1 2 3 4 5 6 7 8 9 |
jQuery(document).ready(function(){ mailtoellements = jQuery("a[href^='mailto:']"); mailtoellements.each(function(item){ mailto = jQuery(this).attr('href'); jQuery(this).attr('href',mailto.replace(/_\[\at\]\_/gi,"@")); email = jQuery(this).html(); jQuery(this).html(email.replace(/_\[\at\]\_/gi,"@")); }); }); |
line 2: Gather all the elements with the matched criteria
line 3: Iterate on these elements
line 4: on each loop get the href attribute value of the current element (which is “peter_[at]_example.com”)
line 5: rewrite the href attribute value to “whatever@whatever” from “whatever_[at]_whatever”
line 6: get the html content of the current element
line 7: rewrite the html content of the current element
Geeks are sexy… :D