code_junkie

Making email addresses safe from bots on a webpage?

Nov 11th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1.  
  2. joe.somebody@company.com
  3.  
  4. function XOR_Crypt(EmailAddress)
  5. {
  6. Result = new String();
  7. for (var i = 0; i < EmailAddress.length; i++)
  8. {
  9. Result += String.fromCharCode(EmailAddress.charCodeAt(i) ^ 128);
  10. }
  11. document.write(Result);
  12. }
  13.  
  14. XOR_Crypt("êïå®óïíåâïäùÀãïíðáîù®ãïí");
  15.  
  16.  
  17. joe.somebody AT company.com
  18.  
  19. <a href="#" class="--mailto--john--domain--com-- other classes goes here" />
  20.  
  21. // match all a-elements with "--mailto--" somehere in the class property
  22. $("a[class*='--mailto--']").each(function ()
  23. {
  24. /*
  25. for each of those elements use a regular expression to pull
  26. out the data you need to construct a valid e-mail adress
  27. */
  28. var validEmailAdress = this.className.match();
  29.  
  30. $(this).click(function ()
  31. {
  32. window.location = validEmailAdress;
  33. });
  34. });
  35.  
  36. <a href="mailto:[email protected]"
  37. onclick="this.href=this.href.replace(/hatestogetspam/,'')">
  38.  
  39. Dim rxEmailLink As New Regex("<ab[^>]*mailto:b[^>]*>(.*?)</a>")
  40. Dim m As Match = rxEmailLink.Match(Html)
  41. While m.Success
  42. Dim strEntireLinkOrig As String = m.Value
  43. Dim strEntireLink As String = strEntireLinkOrig
  44. strEntireLink = strEntireLink.Replace("'", """") ' replace any single quotes with double quotes to make sure the javascript is well formed
  45. Dim rxLink As New Regex("(<ab[^>]*mailto:)([w.-_^@]*@[w.-_^@]*)(b[^>]*?)>(.*?)</a>")
  46. Dim rxLinkMatch As Match = rxLink.Match(strEntireLink)
  47. Dim strReplace As String = String.Format("<script language=""JavaScript"">document.write('{0}{1}{2}>{3}</a>');</script>", _
  48. RandomlyChopStringJS(rxLinkMatch.Groups(1).ToString), _
  49. ConvertToAsciiHex(rxLinkMatch.Groups(2).ToString), _
  50. rxLinkMatch.Groups(3), _
  51. ConvertToHtmlEntites(rxLinkMatch.Groups(4).ToString))
  52. Result = Result.Replace(strEntireLinkOrig, strReplace)
  53. m = m.NextMatch()
  54. End While
  55.  
  56. Public Function RandomlyChopStringJS(ByVal s As String) As String
  57. Dim intChop As Integer = Int(6 * Rnd()) + 1
  58. Dim intCount As Integer = 0
  59. RandomlyChopStringJS = ""
  60. If Not s Is Nothing AndAlso Len(s) > 0 Then
  61. For Each c As Char In s.ToCharArray()
  62. If intCount = intChop Then
  63. RandomlyChopStringJS &= "'+'"
  64. intChop = Int(6 * Rnd()) + 1
  65. intCount = 0
  66. End If
  67. RandomlyChopStringJS &= c
  68. intCount += 1
  69. Next
  70. End If
  71. End Function
  72.  
  73. <script language="JavaScript">document.write('<a '+'clas'+'s='+'"Mail'+'Link'+'" hr'+'ef'+'="ma'+'ilto:%69%6E%66%6F%40%62%69%63%75%73%61%2E%6F%72%67">&#105;&#110;&#102;&#111;&#64;&#98;&#105;&#99;&#117;&#115;&#97;&#46;&#111;&#114;&#103;</a>');</script>
Add Comment
Please, Sign In to add comment