4 replies [Last post]
herrslime
Offline
newbie
42:29:10N 83:22:32W
Last seen: 18 years 16 weeks ago
42:29:10N 83:22:32W
Timezone: GMT-5
Joined: 2004-08-12
Posts: 10
Points: 0

Anybody know a way to hide email addresses on a web site so the spam bots cant't find them. I do not want to use forms right now but I have heard there is a way to do this and still use a mailto link.

I know this is not a CSS question but figured you guys would know.

Thanks

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 4 years 8 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

Spam proof email addresses

Stu
Stu's picture
Offline
Enthusiast
Bristol uk
Last seen: 18 years 45 weeks ago
Bristol uk
Joined: 2004-01-20
Posts: 282
Points: 0

Spam proof email addresses

My method doesn't include a mailto: though.

AFAIK there is no way round this without using javascript etc.

It's not what you do it's the way that you do it.
So do it with STYLE
http://www.s7u.co.uk

herrslime
Offline
newbie
42:29:10N 83:22:32W
Last seen: 18 years 16 weeks ago
42:29:10N 83:22:32W
Timezone: GMT-5
Joined: 2004-08-12
Posts: 10
Points: 0

Spam proof email addresses

Stu;
Very interesting.

I don't have a problem with using javascript. Any suggestions appreciated.

Thanks

Stu
Stu's picture
Offline
Enthusiast
Bristol uk
Last seen: 18 years 45 weeks ago
Bristol uk
Joined: 2004-01-20
Posts: 282
Points: 0

Spam proof email addresses

Javascript ~

function demung(email)
	{
	if (email.indexOf("mailto:") == 0)
		{
		email = email.substring("mailto:".length, email.length);
		}
	var lastDot = email.lastIndexOf(".");
	var numb = parseInt(email.substring(lastDot+1, email.length));
	email = email.substring(0, lastDot);
	var email1 = email.substring(0, numb);
	var email2 = email.substring(numb, email.length);
	email = email1 + "@" + email2;
	return "mailto:" + email;
	}

function loopLinks()
	{
	var l;
	if (document.links) l = document.links;
	else return;
	for (var i=0; i<l.length; i++)
		{
		if (l[i].href.indexOf("mailto:") == 0 && l[i].href.indexOf("@") == -1)
			{
			l[i].href = demung(l[i].href);
			}
		}
	}

save as edecode.js

html to include ~

<script src="http://www.website.com/include/edecode.js" type="text/javascript"></script>

html to add mail link ~

<a href="mailto:saleswebsite.co.uk.5">[email protected]<span class="noview">Not valid</span>mag.co.uk</a>

Line to run javascript (last line on page)

<script type="text/javascript">if (loopLinks) loopLinks();</script>

CSS
.noview {display:none;}

How it works ~

the mailto: address is written WITHOUT the @ and a number is added at the end to indicate where the @ should go. In the above example the @ should be after the 5th characters from the left ~

The javascript routine searches for every "mailto:" and puts the @ back in place BEFORE the page is displayed. If you view the source code you will still see the incorrect mailto:

The CSS removes the <span> from the email address displayed.

You can see this in action on one of my old sites at
http://www.redcliffe.org.uk/index.php

at the bottom of the page is an email link ~ check the source code Smile

It's not what you do it's the way that you do it.
So do it with STYLE
http://www.s7u.co.uk