Protect your email address with JavaScript

20 January 2009| No Comment| Print

Spam is still an increasing problem on the internet and here’s a quick way that you can save your email address from getting poached. This method uses concatenation to bind the email address, The first operator, called the string operator, is the plus sign ( + ). It is used to signify that one whole string is to be ‘added’ to another whole string. for example in our script we have the following line.

 var emailaddress = ('youremail@' + 'emailaddress.com')

The next line just writes an HTML ‘a’ tag on our page with a mailto link to our email address that is now in the variable ‘emailaddress’

 document.write('<a href="mailto:' + emailaddress + '">' + emailaddress + '</a>')

Here’s the complete code:

 var emailaddress = ('youremail@' + 'emailaddress.com')
document.write('<a href="mailto:' + emailaddress + '">' + emailaddress + '</a>')

It may be an idea to add <noscript> </noscript>  tags for anyone that has Javascript disabled, telling them that they won’t be able to see your email address.


Share:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • DZone
  • Reddit
  • Netvibes

Leave a comment...

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled site. To get your own globally-recognized-avatar, register at Gravatar.

Your Ad Here