It’s an unfortunate thing, but the internet certainly has its share of evil people. In my opinion, the worst amongst these are those that deploy software robots to roam the web and harvest email addresses from web pages. These addresses are then collated into massive databases and sold for spam.
Now we all hate spam, and anything that can be done to reduce it is very worthwhile. This is not rocket science, and basic knowledge of HTML and how to cut and paste will see you protected from the spambots. All we are going to use is a bit of javascript.
First, open Notepad or any text editor and then copy and paste the following into the file.
/* This script provides for a specific email address on a web page.
On your web page, add the following:-
blocker(“insert first part of email address”) */
function blocker(name)
var domain =”yourdomainname.com”;
document.write(” + name + ‘@’ + domain + ”);
/* This script adds a subject field to the email.
function blockersubject(name,subject)
var domain =”yourdomainname.com”;
document.write(” + name + ‘@’ + domain + ”);
/* This script is for use as an “Email Us” or likes in a menu system or on a page
Insert the following in your web page:-
blocker2(‘First Part of Email,’’The text you want to appear on the web page’);
function blocker2(name,text)
var domain =”yourdomainname.com”;
document.write(” + text + ”);
/* This script allows the adding of a subject but also displayable text for a menu system. On your web page, place the following:-
blockersubject2(‘first part of email address,’’The Subject in the email,’’The text to appear in the email’);*/
function blockersubject2(name,subject,text)
var domain =”yourdomainname.com”;
document.write(” + text + ”);
//End of file.
Save the file as blocker.js in your document folders because this script can be reused over and over for as many different web pages as you like. You only need to change the variables at hand.
To get the scripts to work, there are a couple of things you need to do. I usually create a sub-directory for my javascript and call it that. Any javascript for the web page can be stored there. Save a copy of the file blocker.js to this directory and then edit all the variables to suit your site.
Now you need to allow the scripts to be called, and the web page needs to know where they are. The easiest way to achieve this is to have the information in the section of your document. Before the closing tag, and assuming you have saved the file to a javascript sub-directory, insert the following line of code:-
(Insert less than sign)script type=”text/javascript” src=”javascript/common.js”>(insert less than sign)/script>
You will have to make sure that the path to the javascript sub-directory is correct for the document. This is simple if you use Dreamweaver to modify the template for your site, and it will update all the pages. If you are using PHP includes, you will need to ensure that the path is correct from your header template to the javascript directory. A little playing will usually get this sorted out for you.
One final thing that you should be aware of is that not everyone has javascript turned on. If a visitor hits your page and has javascript turned off, they won’t see your email addresses at all. To resolve this, enter the following code just below the area where the email address is supposed to appear.
(Insert less than sign)noscript>If you see this, then Javascript is not turned on in your browser, and you won’t be able to see our email addresses. Javascript hides them. You can either turn your Javascript on or alternately email us at your address at domain name dot com(insert less-than sign)/noscript>
Make sure you do not use the @ sign or put the dot in, or even type the full email address correctly. You will destroy all the good work you’ve done.
And there you have it. A simple piece of javascript that will prevent your email address from being harvested by the nasty little bots that roam the web.
You must be logged in to post a comment.