Hiding from Email Harvesters
12
Here's a simple JavaScript solution to hide your e-mail from many spam scripts while still providing clickable hyperlinks to your visitors.
Web crawlers and visitors with JavaScript disabled will see: me [at] mydomain [dot] com. I've seen a lot of people that just leave it at this, but it seems a bit unprofessional in my opinion. With the following code, we can replace that with a fully functional hyperlink.
Web crawlers and visitors with JavaScript disabled will see: me [at] mydomain [dot] com. I've seen a lot of people that just leave it at this, but it seems a bit unprofessional in my opinion. With the following code, we can replace that with a fully functional hyperlink.
<span class="encoded-email">me [at] mydomain [dot] com</a>
function decodeEmails () {
if (document.getElementsByTagName) {
var spans = document.getElementsByTagName("span");
for (var n = 0; n < spans.length; n++) {
if (spans[n].className == "encoded-email") {
var email = spans[n].firstChild.nodeValue.replace(" [at] ", "@");
email = email.replace(" [dot] ", ".");
var hyperlink = document.createElement("a");
var linkText = document.createTextNode(email);
hyperlink.href = "mailto:" + email;
hyperlink.title = "Send me an e-mail";
hyperlink.appendChild(linkText);
spans[n].replaceChild(hyperlink, spans[n].firstChild);
linkText = null;
hyperlink = null;
}
}
}
}
Just call the decodeEmails() function using your favorite window load event handler. if (document.getElementsByTagName) {
var spans = document.getElementsByTagName("span");
for (var n = 0; n < spans.length; n++) {
if (spans[n].className == "encoded-email") {
var email = spans[n].firstChild.nodeValue.replace(" [at] ", "@");
email = email.replace(" [dot] ", ".");
var hyperlink = document.createElement("a");
var linkText = document.createTextNode(email);
hyperlink.href = "mailto:" + email;
hyperlink.title = "Send me an e-mail";
hyperlink.appendChild(linkText);
spans[n].replaceChild(hyperlink, spans[n].firstChild);
linkText = null;
hyperlink = null;
}
}
}
}






Sorry, careless mistake.