If your website is 100% statically served and has no access to dynamic technologies like php or dot net languages. You would need to use a tool or create some sort of anti bot counter measures through encapsulation or encoding.
I find the most effective method is to create an image but this would require the end user to physically type in what they see in the image. The best thing about images is that it would require a decoder to convert from image to text during there scraping process.
I've researched several methods using encoding and image creation.
First Method (works without modification)
Loop through each character in the email address link (including the mailto: protocol prefix) with the charCodeAt()
function of the String
object. Then prepend with &#
and postfix with ;
this value can be used with the anchor tag href attribute directly.
The first method can also use base 16 numbers by prepending with &#x
and postfix with ;
but would require manual decoding to base 10 using parseInt(value, 16)
and then using fromCharCode()
from the String
object.
Second Method (requires the user to copy the value)
Create a DataURL using the text/html
mimetype. The data url should contain a base 64 encoded html page using btoa()
which contains a meta refresh tag with the encoded mailto
email address link. This would essentially encapsulate the email address entirely.
The DataURL would look something like this (working link)
data:text/html;charset=utf-8;base64,PGh0bWw+PGhlYWQ+PG1ldGEgaHR0cC1lcXVpdj0icmVmcmVzaCIgY29udGVudD0iMDsgVVJMPW1haWx0bzomIzEwMTsmIzEwOTsmIzk3OyYjMTA1OyYjMTA4OyYjNjQ7JiMxMDA7JiMxMTE7JiMxMDk7JiM5NzsmIzEwNTsmIzExMDsmIzQ2OyYjOTk7JiMxMTE7JiMxMDk7IiAvPjwvaGVhZD48L2h0bWw+
Example Meta Tag
<meta http-equiv="refresh" content="0; URL=mailto:BASE_10_ENCODED_EMAIL_ADDRESS" />
This meta tag would cause a redirect to the mailto
link as it normally would by directly entering it in the address bar. The second method also works with JavaScript but you would be required to manually decode the string using the fromCharCode()
then input this into the window.location.href
. Using the second method also allows for a timeout of nth seconds if you wish.
Third method (requires an external tool)
Create a simple image that contains the email address in pixels there are many tools online to achieve this.
Fourth Method (requires decoding)
Use a UTF-8 encoded string. You can encode the entire value of the mailto
protocol and email address using the \u
UTF-8 escape sequence. This is similar to the first method but would require manual decoding. The best package for this would be jconv
which has an encode and decode function in the module.
Each of the four methods described above can be demonstrated by the tools i have created.
- Email Address Encoded
- Email Address DataURL
- Email Address Image
- Email Address UTF-8