No Spam Email Link
So you’ve created a website and want people to be able to email you from the web site. You could put your email address on the web page as text (username@domain.com). You could also put your email address as a hyperlink.
The problem with both of these methods is they are susceptible to spam. Spammers use programs that crawl the web collecting email addresses. It’s an efficient way to compile a mailing list.
You could use an email form. Those are somewhat complex and there are scripts that use those to send spam. If you have the programming skills, a form based solution is a good choice.
Another way to do it is to use JavaScript. This is my favorite method because it’s simple, easily customizable and extremely flexible. You will need to know some basic HTML, but you just created a webpage, so you probably have the skills you will need for this. The JavaScript is quite simple.
If you are somewhat familiar with JavaScript and just want to see the source code, click here.
Here’s some background information on how and why it works. The programs that spammers use to crawl the web are not humans. They “read” the HTML and do not display it in a client such as Internet Explorer or Firefox. JavaScript is a type of programming called client side scripting. Essentially, it runs on the client machine and not on the server. So when you visit a page that has JavaScript, that script is run on you local machine.
One of the things you can do with JavaScript is alter the HTML on the page being displayed. Is this case we will do this using a JavaScript command called “document.write”. This command will write to the document. Yes, sometimes programming is that simple.
Another thing you can do with JavaScript is build a string with multiple variables. A string is one or more characters. This sentence is a string. 123546 is also a string, but can be used a numeric variable. We will only use string variables in this project.
To create an email link in html you use the anchor tag.
<a href="mailto:username@domain.com">HTML</a>
To do this with Javascript you could use the command:
document.write("<a href='mailto:username@domain.com'>sometext<\/a>")
This will insert the following string wherever the command is run.
<a href="mailto:username@domain.com">HTML</a>
You could also assign the string to a variable and then display the variable like this:
myvariable="<a href='mailto:username@domain.com'>sometext<\/a>"
document.write(myvariable)
If the email harvesting program is savvy enough, it will pull your email address from the script file. To prevent this, break the email address into multiple strings and reassemble them with document.write.
urname="username"
at="@"
domnname="domain.com"
text="email"
title="Click here to send me an email."
document.write("<a href='mailto:"+urname+""+at+""+domnname+"' title='"+title+"'>"+text+"<\/a>")
I prefer using external script to using inline script. I won’t go over the arguments for the different styles; I also won’t go over the arguments for and against the designated hitter rule. To use it with external script you save the text to a file with the “js” extansion. Something like emailscript.js. Then you will need to insert the HTML code:
<script language="JavaScript" type="text/javascript" src="emailscript.js"></script>
Insert the HTML code wherever you want the link to appear. Here is an example of my script. If you hover your cursor over the link you will notice a tooltip with the text from the “text” variable.
Here is a link to a text file containing the JavaScript code. You will need to change the variables to fit your email address. You will also need to save it with a “js” extension, or rename it after you save it.
Feel free to use the script as long as you don't resell the script itself. If you feel like linking to me that would also be appreciated.