Search
register | login   Friday, November 21, 2008
West Michigan .NET User Group Discussion

SearchForum Home
     
  Feedback  Website Issues, Comments, Suggestions  protect email a...
 protect email addresses with javascript
 
 10/17/2007 12:30:55 AM
terrydavidson
1 posts


protect email addresses with javascript

If you put any email addresses on your website for visitors to contact someone you need to protect the link from SPAM harveser programs. Spelling out the email address in the text or ***ociating a valid email address with alternate text will surely be harvested and those email addresses will be added to SPAM lists. I have found that by using a very simple javascript code that has been circulating around the intyernet for years has worked wonderfully at providing valid links without the ability to be harvested,

Basically you define 3 variables, one for the actual text to be displayed, one for the first part of the email address (before the @ symbol) and one variable for the domain name. The script is broken up into parts and between basic script commands and the variables it puts the link together.

Here is an example of what I like to use:

<script language=javascript>
  <!--
  var recipient = "Name to Display"
  var email = "user_account"
  var Host = "domain"
  document.write("<a href=" + "mail" + "to:" + email + "@" + Host+ ">" + recipient + "</a>")
  //-->
</script> 

The document.write command with the variables will ***emble the email address properly. You can change the name of your variables as long as you change them in the command string.

Just remember that it does use Javascript so if a person has javascript blocked or turned off within their browser it will not work. Currently the statistics say that 99.7% of users have javascript enabled within their browser, so it would be a small percentage.

  Feedback  Website Issues, Comments, Suggestions  protect email a...
 
Website By
Sponsored By
Partner Michigan .Net User Groups