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 392,009 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 4,269 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

Obfuscating email addresses in HTML

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  
All times are GMT -4. The time now is 10:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC