email munging using javascript for wordpress
Anyone who wants to post their email address on the Internet should be wary of spiders picking up their address and filling their inbox with spam. Here’s a little trick that hopefully keeps your email address hidden from spiders, but allows normal users view it easily.
This will actually work anywhere you can get JavaScript to run. In the case of WordPress, there’s issues getting JavaScript to run directly in a post. So what I did was created a contact page. Within the contact page I put:
If you'd like to contact me about anything at all, feel free to email
me at <span id="foo">test</span> or send me an IM on google talk.
<script language="javascript">
//<code>
a = ["mai", "lto", "benjamin", "lee", "smith", "gm", "ail", "com"];//
b = a[0]+a[1]+":"+a[2]+"."+a[3]+"."+a[4]+"@"+a[5]+a[6]+"."+a[7];//
c = a[2]+"."+a[3]+"."+a[4]+"@"+a[5]+a[6]+"."+a[7];//
document.getElementById("foo").innerHTML = "<a href=""+b+"">"+c+"";//
//</code>
</script>
When the page loads, the contents of the span will be replaced with my email address. My email address is pieced together from the contents of an array, which I think obfuscates my email enough such that spiders (unless they’ve started executing JavaScript) won’t be able to understand.
There are also a couple of other hacks going on here to get it to work in Wordpress. The code tags only exist to keep wordpress from touching the JavaScript syntax and escaping things like the greater than and less than characters. The code tags themselves are commented out, so that the JavaScript won’t worry about them being inside of the script tags. And at the end of every line of JavaScript there is an empty line comment, to escape anything that WordPress puts at the end of a line. If you’re not dealing with Wordpress, these things can be omitted.




