Simple Javascript to Combat Spam
Monday, August 25th, 2008Before you read any further, take into context this isn’t going to fully help you in terms of lessening your spam. However, it is a neat trick and will help some, or at least deter some spamming bots from picking your e-mail address and using it for spam.
While at work today I was performing some maintenance on a project that was handed to me and I noticed a tiny bit of javascript used to print an e-mail address, but by doing so kept it seperate and not connected.
<script type="text/javascript">
emailE=('roberthash@' + 'yahoo.com')
document.write('<A href="mailto:' + emailE + '">' + emailE + '</a>')
</script>
What you see first is that a variable is assigned two values that are added together. By splitting the e-mail into two pieces (in theory), this will assist in deterring spam bots searching for a valid e-mail address.
emailE=('roberthash@' + 'yahoo.com')
From there we utilize the document.write() function to print this text to the browser window.
document.write('<A href="mailto:' + emailE + '">' + emailE + '</a>')
Another beautiful part is that if Javascript is not installed, this means there won’t be an e-mail address showcased. However, this could be a pain if you have someone trying to find your e-mail address that has a legit reason to contact you - but doesn’t have Javascript.
As usual, it is a method to be used at your own risk or if you feel it is indeed the solution for your project.
With further research, I have found the origination of this code, which can be found at http://www.joemaller.com/js-mailer.shtml.
As you can see - it is a very simple approach that even a novice programmer can understand. Who says you can’t learn new tricks?