/    Sign up×
Community /Pin to ProfileBookmark

Hide e-mail addresses from bots

I found this script at javascripts.com and am wondering how to deploy the script on my site, does the script replace my existing hrefs on my contacts page? I don’t fully understand document.write, obviously.

<!– Begin
user = “username”;
site = “yoursite.com”;

document.write(‘<a href=”mailto:’ + user + ‘@’ + site + ‘”>’);
document.write(user + ‘@’ + site + ‘</a>’);
// End –>

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayJan 07.2004 — It just constructs a link and writes it to the current document. If you want it on top of the page you can place it in the <head><script> area, if you want it somewhere else on the page place it between <script> and </script> tags in the document body.
Copy linkTweet thisAlerts:
@oleragJan 07.2004 — If you play with this you'll get a better idea of what "BearMay"

has already explained...

[code=php]
<html>
<head>
<script type="text/javascript">
function showNewMail() {
var user = "username";
var site = "yoursite.com";

document.write('<a href="mailto:' + user + '@' + site + '">');
document.write(user + '@' + site + '</a>');
}
</script>
</head>
<body>
A little text...
<form>
<input type="button" value="Replace" onClick="showNewMail()">
</form>
<script type="text/javascript">
showNewMail();
</script>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@cadboyauthorJan 07.2004 — Okay, let me put it to you this way, I have a contacts page that lists staff and the names are the links to their e-mails, in that format is there away of preventing the bots from reading the e-mail adresses or do I have to change the page to incorporate this script?

Thanks for helping out a hopeless newbie!
Copy linkTweet thisAlerts:
@FangJan 08.2004 — Here are a couple of links that generate the code for you:

[URL=http://www.codehouse.com/webmaster_tools/webmaster/email_obfuscator/]E-mail Obfuscator[/URL]

[URL=http://www.mways.co.uk/prog/hidemail.php]mways IT[/URL]
Copy linkTweet thisAlerts:
@cadboyauthorJan 08.2004 — Obfuscator - I was trying to think of just such a word to look around for something just link you kindly gave me links to!

Thanks for the help, eh!

Next time you're in Vancouver, BC let me buy you a pint!
Copy linkTweet thisAlerts:
@oleragJan 08.2004 — Both sites hide their "hex" jumble code in JS scripts. Here's

a sample that resembles Fang's link to [i]mways[/i]

approach with HTML...

[code=php]
<html>
<head>

<script type="text/javascript">
<!-- Converts a text string value to a formatted Hexidecimal string -->
function getHexString(val) {
var hexStr = "";
if (val.length > 0) {
for (var i=0; i<val.length; i++) {
hexStr += "%" + getHexVal(val.charCodeAt(i));
}
}
return(hexStr);
}

<!-- Converts a text string value to a formatted Unicode string -->
function getUnicodeString(val) {
var uniStr = "";
if (val.length > 0) {
for (var i=0; i<val.length; i++) {
uniStr += "&#" + val.charCodeAt(i) + ";";
}
}
return(uniStr);
}

<!-- Converts a Unicode char value to hexidecimal equivalent -->
function getHexVal(unicodeVal) {
hexChars = "0123456789ABCDEF";
var i = unicodeVal%16;
var j = (unicodeVal-i)/16;
return(hexChars.charAt(j) + hexChars.charAt(i));
}

<!-- Accecpts a textual email "val" and optional "label" and returns -->
<!-- the formatted HTML anchor tag statement. The email "val" will be -->
<!-- converted to hexidecimal format and the label information will -->
<!-- be converted to Unicode. If the "label" is not provided, the -->
<!-- email "val" value will be substituted. -->
function getObsfucateEmail(val,label) {
var obsEVal = "";
var obsLbl = "";

if (val.length > 0) {
if (label.length == 0) {
label = val;
}
obsEVal = "<a href="mailto:" + getHexString(val) + "">";
obsLbl = getUnicodeString(label) + "</a>";
}
return(obsEVal + obsLbl);
}

function openPop() {
var popWin = window.open("","popWin");

popWin.document.open();
popWin.document.write(getObsfucateEmail(document.forms[0].field1.value, document.forms[0].field2.value));
popWin.document.close();
}
</script>
<body>
<form>
Email: <input type="text" name="field1" size="40"><br>
Label: <input type="text" name="field2" size="40"><br>
<textarea name="area1" rows="5" cols="80" disabled="disabled"></textarea><p>
<input type="button" name="btn1" value="Display" onClick="this.form.area1.value=getObsfucateEmail(this.form.field1.value, this.form.field2.value)">
<input type="button" name="btn2" value="Send" onClick="openPop()">
</form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@cadboyauthorJan 08.2004 — Again thanks for that, my understanding of the script is now light years ahead of where I was a couple of days ago.

This seems to provide some protection, however I imagine that the bots are getting even more intuative?

Are there other steps that can be taken to prevent these malicious little buggers?
Copy linkTweet thisAlerts:
@PittimannJan 08.2004 — Hi!

You'd have much more security, if you can use a server side language like PHP. It would not be necessary to make your address visible to users and bots; you could just use a form and a serverside script would do the job (e.g. directing the mail to the desired address depending on a keyword stored in a hidden form field)...

Cheers - Pit
Copy linkTweet thisAlerts:
@cadboyauthorJan 08.2004 — Or maybe ColdFusion?
×

Success!

Help @cadboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...