Jscript to obscure emails from robots in HTML
This script will obscure email addresses from robots even ones that ignore the
tags to not snoop. Usually robots that ignore the tags, and the robots.txt file
are used by spammers. They pull down the SOURCE of your page and scrape the
email addresses from them. This script breaks the mail href into its base parts
and uses overloading so that you may call it with any of its parameters. I know
this forum is for SQL Server, but many of us output that data via web pages, so
I am posting this to help in the war against spammers. To test out, copy the
below script into an html file, and open with IE or Netscape with JavaScript
enabled. Spam Delenda Est
For more info : http://support.microsoft.com/default.aspx?scid=kb;EN-US;217103
<HTML>
<HEAD>
<title>Email Test</title>
<SCRIPT LANGUAGE=javascript>
<!--
function WriteEmail(varTo, varToDomain)
{
WriteEmail(varTo, varToDomain, null, null, null, null, null, null, null);
}
function WriteEmail(varTo, varToDomain, varToEmailDisplayName)
{
WriteEmail(varTo, varToDomain, varToEmailDisplayName, null, null, null, null, null, null);
}
function WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject)
{
WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject, null, null, null, null, null);
}
function WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject, varBody)
{
WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject, varBody, null, null, null, null);
}
function WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject, varBody, varCC, varCCDomain)
{
WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject, varBody, varCC, varCCDomain, null, null);
}
function WriteEmail(varTo, varToDomain, varToEmailDisplayName, varSubject, varBody, varCC, varCCDomain, varBCC, varBCCDomain)
{
//Author:Tim Cartwright
//Purpose : Overloaded WriteEmail function used to display href's that will not get scraped by the robots
// IMPORTANT:
// If you add this script to a script-library or script-archive
// Leave my name as the original author, otherwise feel free to use or modify
var varAtSymbol = String.fromCharCode(64);
var varToEmail = varTo + varAtSymbol + varToDomain;
var varCCEmail = '';
var varBCCEmail = '';
var varToEmailSubject = '';
var varToEmailBody = '';
if (varToEmailDisplayName == undefined)
varToEmailDisplayName = varToEmail;
if ((varCC != undefined && varCC != '') && (varCCDomain != undefined && varCCDomain != ''))
varCCEmail = '&CC=' + varCC + varAtSymbol + varCCDomain;
if ((varBCC != undefined && varBCC != '') && (varBCCDomain != undefined && varBCCDomain != ''))
varBCCEmail = '&BCC=' + varBCC + varAtSymbol + varBCCDomain;
if (varSubject != undefined && varSubject != '')
varToEmailSubject = '&Subject=' + varSubject;
if (varBody != undefined && varBody != '')
varToEmailBody = '&Body=' + varBody;
document.write('<A href="mailto:' + varToEmail + varCCEmail + varBCCEmail + varToEmailSubject + varToEmailBody + '">' + varToEmailDisplayName + '</A>');
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<P>Testing writing an email out. Robots will have a hard time scraping email addresses as the source does not contain any. This script will let you build a complete or partial href including:</P>
<OL>
<LI>To - The main recipient of the mail.
<LI>CC - Carbon Copy recipient.
<LI>BCC - Blind Carbon Copy recipient.
<LI>Subject - Subject of the email.
<LI>Body - Body of the email.
</OL>
<P>Examples:</P>
<SCRIPT LANGUAGE=javascript>
<!--
document.writeln('toname + todomain<BR>');
WriteEmail('tcartwright', 'toaddress.com');
document.writeln('<BR><BR>');
document.writeln('toname + todomain + display name<BR>');
WriteEmail('tcartwright', 'toaddress.com', 'Tim Cartwright');
document.writeln('<BR><BR>');
document.writeln('toname + todomain + display name + subject<BR>');
WriteEmail('tcartwright', 'toaddress.com', 'Tim Cartwright', 'Test Subject');
document.writeln('<BR><BR>');
document.writeln('toname + todomain + display name + subject + body<BR>');
WriteEmail('tcartwright', 'toaddress.com', 'Tim Cartwright', 'Test Subject', 'Test Body');
document.writeln('<BR><BR>');
document.writeln('toname + todomain + display name + subject + body + cc address + cc domain<BR>');
WriteEmail('tcartwright', 'toaddress.com', 'Tim Cartwright', 'Test Subject', 'Test Body', 'tcartwright', 'ccaddress.com');
document.writeln('<BR><BR>');
document.writeln('toname + todomain + display name + subject + body + cc address + cc domain + bcc address + bcc domain<BR>');
WriteEmail('tcartwright', 'toaddress.com', 'Tim Cartwright', 'Test Subject', 'Test Body', 'tcartwright', 'ccaddress.com', 'tcartwright', 'bccaddress.com');
document.writeln('<BR><BR>');
document.writeln('toname + todomain + display name + subject + body + null cc + bcc address + bcc domain<BR>');
WriteEmail('tcartwright', 'toaddress.com', 'Tim Cartwright', 'Test Subject', null, null, null, 'tcartwright', 'bccaddress.com');
document.writeln('<BR><BR>');
//-->
</SCRIPT>
</BODY>
</HTML>