Login

email rendered via javascript (trick spam crawlers)

Author:
rizumu
Posted:
August 3, 2009
Language:
HTML/template
Version:
Not specified
Tags:
template email
Score:
0 (after 0 ratings)

The proper looking email links rendered to the browser are not in the source code that way, and are rendered by javascript, so robots can't extract it. Its a trick way to have the email displayed properly without getting spamed as a result.

Unless the robots are getting smarter, this has worked for me thus far.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# model
email = models.EmailField(max_length=75, blank=True)

def emailname(self):
    email = self.email.rpartition('@')
    return email[0]

def emailserver(self):
    emailserver = self.email.rpartition('@') 
    return emailserver[2]
    
# template
{% if object.email %}
<script type="text/javascript">
  emailname = "{{ object.emailname }}";  		
  emailserver = "{{ object.emailserver }}";  		
  document.write("<a href=\'mailto:" + emailname + "@" + emailserver + "\'>" + emailname + "@" + emailserver + "</a>");
</script>
{% endif %}

# browser
name@server.com

More like this

  1. Email and phone templatetag obfuscator by sunn 5 years, 7 months ago
  2. Email Munger by cootetom 6 years, 1 month ago
  3. Render to file by jacobian 6 years, 11 months ago
  4. Partial JSON template rendering by barbuza 7 years, 4 months ago
  5. Email Auth by petzah 10 months, 1 week ago

Comments

rizumu (on August 15, 2009):

Also check out the next snippet 1666 which performs a far more cryptic job of cloaking the text. Unfortunately with that solution using mailto: link, verbatim text remains in the source available for scraping. I think I'll try a combination of these two for ultimate transparency.

#

rizumu (on August 15, 2009):

Realized if careful about passing different variables for email and title 1666 does entirely cloak the tag. The robots are smarter :/

#

Please login first before commenting.