No Spam Please!
Don’t you really hate it when you put your email address online and bots start to spam it? Me too! Upon launching a new site, I decided to do something about it.
Here is a very simple script that displaces the issue of having mailto: links laying about in your code for spam bots to pick up.
function hide_email()
{
//create regular expression
var regular_expression = new RegExp(”[Mm]ailto”);
//start by checking all links
for(var count=0; count<document.links.length; count++)
{
//is this an email link??
if(regular_expression.test(document.links[count].href))
{
try {
//move email link for safe keeping
document.links[count].name = document.links[count].href;
//replace email link with nonsense
document.links[count].href=”mailto:nospam@nospam.com”;
//keep valid users happy (yay!)
document.links[count].onmouseover = function() { this.href = this.name; };
//keep spammers away (boo bots!)
document.links[count].onmouseout = function() { this.href=”mailto:nospam@nospam.com”; };
}catch (err) {
//oh noes! something bad happened.
}//end catch
}//end if
}//end for loop
}//end hide emailhide_email(); //make function call to execute
Now put this script, right before the </body> (yes ending body tag) tag and it will scour your web page for all mailto: links and save them from bot doom. Of course this isn’t an extremely secure fix, but it’ll do the job against those stupid bots until they get smarter.
Final Note: If you’re using my script for tooltips, then these two aren’t compatible together yet. I think I understand the problem, but it’ll take some testing to verify. Just give me some time and I’ll make a post with new versions.
Tags: bot, email, fix, hide, javascript, mailto, no, no spam, safe, secure, security, spam, spambot












April 8th, 2008 at 7:46 am
Example please.
April 8th, 2008 at 9:34 am
HoltkampW.com is running at it. There are currently 2 mailto links. If you view source, both of the URLs a modified so you the bot can’t find it if searching for the href field.
I stored it in the name field, which obviously is still viewable in the source. If you can think of a better spot to store it in the DOM that’d be great.
Oh and when you mouseover, a the mailto link is re-created so the user is none the wiser.