Login

email rendered via javascript (trick spam crawlers)

Author:
rizumu
Posted:
August 3, 2009
Language:
HTML/template
Version:
Not specified
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
[email protected]

More like this

  1. Bootstrap Accordian by Netplay4 5 years, 10 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
  4. Reusable form template with generic view by roldandvg 8 years, 11 months ago
  5. Pagination Django with Boostrap by guilegarcia 9 years, 1 month 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.