Markdown natively supports mail obfuscation for emails put in angular brackets. However, if you are using a different markup format (most notably Textile), you do not have any specific support.
To reduce the risk of emails being harvested from my website, I
defined the following function in the
helpers section of my
config.rb file of my MiddlemanApp
Download the snippet, if you want: mail_to.rb.
Usage is pretty simple:
<%= mailto "firstname.lastname@example.org", "send me an mail" %>
<a href="my email when you click" rel="nofollow" onclick="str1='email';str2='example.com';this.href='mailto:' + str1 + '@' + str2">contact me</a>
The script takes also care of obfuscating the email address, if it passes as
the second argument, by replacing
<%= mailto "email@example.com", "firstname.lastname@example.org" %>
<a href="my email when you click" rel="nofollow" onclick="str1='email';str2='example.com';this.href='mailto:' + str1 + '@' + str2">email at example dot com</a>
This might not be the strongest obfuscator available, but it simple and based on a rather effective strategy. See, e.g., Effective method to hide email from spam bots.
… and if you are not happy with it, as long as you use the
consistently in your website, upgrading to a stronger obfuscator becomes a
matter of replacing the code above.
Get in touch