Javascript code to help hide your email address from harvesting bots on web pages

Compliments of CharlesWorks website hosting

Feeling just plain lost at times? Let CharlesWorks help you find your way into website hosting on the Internet!

One of the ways that spammers get email addresses is to harvest them from websites and newsgroups. There are programs that search the web harvesting email addresses from each page they encounter, follow the links on each page, and so on. Having your email address on a web page inadvertently becomes an invitation to spammers.

Here is a short, handy script that will allow one to keep one's email address available yet prevent most spam harvesting bots to find it. The script is placed in place of a piece of text or in place of the html code that provides the hyperlink to generate an email. After the code, an example follows. Note there is a fictitious email address in the example.

 

<SCRIPT type=text/javascript>
<!-- 
emailT='Click here to email me'
emailE='DoNotSpam.Me'
emailE=('Please' + '@' + emailE)
document.write('<a href="mailto:' + emailE + '">' + emailT + '</a>')
//-->
</SCRIPT>

Below is a complete sample html file using the above code.

Note that any text substituted for the "Click here to email me" will be printed. Note also that by using the apostrophe character as the string delimiter, quotation marks may be included in the text.

 

<html>
<head>
<title>Email Address Hider</title>
</head>
<body>
<p>For more information,</p>
<p>
<SCRIPT type=text/javascript>
<!-- 
emailT='Click here to email me'
emailE='DoNotSpam.Me'
emailE=('Please' + '@' + emailE)
document.write('<a href="mailto:' + emailE + '">' + emailT + '</a>')
//-->
</SCRIPT>
</p>
<p>and we will get back to you.</p>
</body>
</html>

If you enter this file using a text editor and save it with a file extension of .htm or .html it will run in your browser upon clicking on it. It should produce the following output in your browser:

 

For more information,

and we will get back to you.

Hope this is helpful!

 

 

©2004-2020 CharlesWorks
PO Box 128, Peterborough, New Hampshire 03458
Phone: 603-924-6759 in USA Mon-Fri 9-5 Eastern time

Website hosting by CharlesWorks
Updated Tuesday, September 15, 2020 at 07:04 pm