User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,788 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,407 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 516 | Replies: 2
Reply
Join Date: Aug 2007
Posts: 52
Reputation: Fest3er is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Fest3er Fest3er is offline Offline
Junior Poster in Training

Solution Obfuscating email addresses in HTML

  #1  
Jan 2nd, 2008
I've created a fairly simple method for obfuscating email addresses as an anti-spam measure. It should work for any browser that supports JavaScript and a fairly modern Document Object Model (DOM). A composer window in the user's default email application will be opened.

First up is the javascript function that assembles the mailto: url and 'submits' it:
  1. <script language="javascript">
  2. // Action taken when an email 'link' is clicked
  3. function local_emclick(parm1, parm2)
  4. {
  5. test_4 = "lto:";
  6. d37 = "@";
  7. t2 = "mai";
  8. parm = t2+test_4+parm1+d37+parm2;
  9. self.location = parm;
  10. }
  11. </script>
You should customize everything (but the script tags and function and self.location) to prevent spammers from learning to recognize the pattern. Even the order of the parameters should be customized.

Next up is the PHP function that eases using this method:
  1. function local_emlink($one, $two, $three, $four, $five="")
  2. {
  3. if ($five!="")
  4. {
  5. $smso = "<b>"; $rmso = "</b>";
  6. }
  7. else
  8. {
  9. $smso = ""; $rmso = "";
  10. }
  11. print("$smso<a class=\"$two\" href=\"about:\" onclick='local_emclick(\"$one\", \"$three\"); return false;'>$four</a>$rmso");
  12. }
An example of its use is:
  1. <p style="text-align:center; margin:2pt 18pt; text-indent:0;
  2. background-color: #CC9966; font-size:7.5pt; font-weight:bold;
  3. text-decoration:underline">
  4. Sample Company<br>
  5. 012 Rhode St.<br>
  6. Notown, MI 00000<br>
  7. (123)555-7890<br>
  8. Fax: (123)555-7891<br>
  9. <?php local_emlink("info", "header", "sample.com", "Contact"); ?>
  10. </p>
If you don't have access to PHP, then you can create the link directly in HTML. This is the same HTML generated by the PHP, except for whitespace::
  1. <a class="header"
  2. href="about:"
  3. onclick='local_emclick("info", "sample.com");
  4. return false;'>Contact</a>
Last edited by Fest3er : Jan 2nd, 2008 at 3:57 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: www.JavaScriptBank.com
Posts: 5
Reputation: temp304 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
temp304's Avatar
temp304 temp304 is offline Offline
Newbie Poster

Re: Obfuscating email addresses in HTML

  #2  
Jan 3rd, 2008
good post, but you should provide demo for these
www.JavaScriptBank.com - 2.000+ free JavaScripts
Start hosting from: $22/year | With promo code: 97USDD | At DreamHost
Reply With Quote  
Join Date: Aug 2007
Posts: 52
Reputation: Fest3er is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Fest3er Fest3er is offline Offline
Junior Poster in Training

Re: Obfuscating email addresses in HTML

  #3  
Jan 3rd, 2008
Originally Posted by temp304 View Post
good post, but you should provide demo for these


Quite right. Do note that if you copy/paste the examples below, you may receive an error. Daniweb's VB seems to insert "<b></b>" between 'about' and ':' in the HTML example.

Minimal PHP example:
  1. <html><body>
  2.  
  3. <?php
  4.  
  5. function local_emlink($one, $two, $three, $four, $five="")
  6. {
  7. if ($five!="")
  8. {
  9. $smso = "<b>"; $rmso = "</b>";
  10. }
  11. else
  12. {
  13. $smso = ""; $rmso = "";
  14. }
  15. print("$smso<a class=\"$two\" href=\"about:\" onclick='local_emclick(\"$one\", \"$three\"); return false;'>$four</a>$rmso");
  16. }
  17. ?>
  18.  
  19. <script language="javascript">
  20. // Action taken when an email 'link' is clicked
  21. function local_emclick(parm1, parm2)
  22. {
  23. test_4 = "lto:";
  24. d37 = "@";
  25. t2 = "mai";
  26. parm = t2+test_4+parm1+d37+parm2;
  27. self.location = parm;
  28. }
  29. </script>
  30.  
  31. <p style="text-align:center; margin:2pt 18pt; text-indent:0;
  32. background-color: #CC9966; font-size:12pt; font-weight:bold;
  33. text-decoration:underline">
  34. Example Company<br>
  35. 012 Rhode St.<br>
  36. Notown, MI 00000<br>
  37. (123)555-7890<br>
  38. Fax: (123)555-7891<br>
  39. <?php local_emlink("info", "header", "example.com", "Contact"); ?>
  40. </p>
  41.  
  42. </body></html>

Minimal HTML example (produce by the above PHP):
  1. <html><body>
  2.  
  3.  
  4. <script language="javascript">
  5. // Action taken when an email 'link' is clicked
  6. function local_emclick(parm1, parm2)
  7. {
  8. test_4 = "lto:";
  9. d37 = "@";
  10. t2 = "mai";
  11. parm = t2+test_4+parm1+d37+parm2;
  12. self.location = parm;
  13. }
  14. </script>
  15.  
  16. <p style="text-align:center; margin:2pt 18pt; text-indent:0;
  17. background-color: #CC9966; font-size:12pt; font-weight:bold;
  18. text-decoration:underline">
  19. Example Company<br>
  20. 012 Rhode St.<br>
  21. Notown, MI 00000<br>
  22. (123)555-7890<br>
  23. Fax: (123)555-7891<br>
  24. <a class="header" href="about:" onclick='local_emclick("info", "example.com"); return false;'>Contact</a></p>
  25.  
  26. </body></html>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:00 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC