Prevent Spammers email collecting with JavaScript
January 16th, 2007 by Ivan Uzunov
Using JavaScript to prevent email addresses harvesting by spammers if an effective method against the standard harvesting programs. Nevertheless the spammers could modify their harvesting programs to read the email addresses from the JavaScript. That is why this is not a bulletproof solution but is really effective and could easily be customized for any web site.
The idea is to create a JavaScript function that will print the email address:
function printEmail(theName, theExtras, theLink, theDomain) {var theEmail = theName + "@" + theDomain;
if (theName == "") {
theName = "ERROR";
theLink = "ERROR";
myEmail = theName;
myLink = theLink;
} else {
if ((theExtras == "") && (theLink =="")){
myEmail = theEmail;
myLink = theEmail;
}
if ((theLink == "") && (theExtras != "")){
myLink = theEmail;
myEmail = theEmail+theExtras;
}
if ((theLink != "") && (theExtras != "")){
myLink = theLink;
myEmail = theEmail+theExtras;
}
if ((theLink != "") && (theExtras == "")){
myLink = theLink;
myEmail = theEmail;
}
}
document.write(’<a href="mailto:’ + myEmail + ‘" class="email">’ + myLink + ‘</a>’);
}
You can call the function using this line of code:
JavaScript, spam<script type="text/javascript">printEmail("ivan", "", "", "gmail.com");</script>



