Search:

JavaScript email cloaking

Here’s another quick one. Below is a simple JavaScript that you can use to cloak your email address when posting it on your website. It dynamically writes the email link into the page which will thwart most spambots (server-side creation of the email link will always be a little more secure). Here’s how we do it…

 
1 – create a new JavaScript file, name it “email.js”, and paste in the following…

var prefix = "username";
var suffix = "domainname.com";
var address = prefix + "@" + suffix;

document.write('<a href="mai');
document.write('lto:' + address + '">click here</a>');

 
2 – then place the following code in your page where you want the link to appear…

<script type="text/javascript" src="email.js"></script>

 
example:

<p>to contact me via email, please <script type="text/javascript" src="email.js"></script></p>

 
result:

to contact me via email, please

 

All you have to do is change 3 variables. The email prefix and suffix are in the first 2 lines of code in the external JavaScript file. The text to display for the hyperlink is in the last line of code (in this case – “click here”). It’s pretty self-explanatory.

 

 

comments

Leave a Reply




     
  • need my help?

    Interested in having me be a consultant on your next project?  to email me.

  •  
  • what i’m reading...

  • Run Windows on Mac OS X with no reboot!ING DIRECT Orange Savings Account- Apply Today!
    BasecampGo Daddy $6.99.com sale 125x125

    Order DIRECTV Today for $29.99 a month