Papermashup

Subscribe


Tweets


"RT @danbarker: Strangely I saw a really shifty guy drop his wallet earlier today in London. When I handed it back he said "Let me give you…"

@ashleyford 7 hours ago

"RT @McDonaldsCorp: Black Friday **** Need copy and link****"

@ashleyford 7 hours ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Protect your email address with JavaScript

AshleyAshley

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 = ('[email protected]' + '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('' + emailaddress + '')

Here’s the complete code:

 var emailaddress = ('[email protected]' + 'emailaddress.com')
document.write('' + emailaddress + '')

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.

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 0
There are currently no comments.