SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    0 Post(s)
    0 Thread(s)

    Is this a good way to obfuscate emails from spammers?

    I was trying to think of a way to show emails on a website and have them hidden from spammers, but still be a clickable link and still be viewable for non-JS devices. I came up with this:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    		<title>Untitled Page</title>
    		<script type="text/javascript"><!--
    function addLoadEvent(func) {
    	var oldonload = window.onload;
    	if (typeof window.onload != 'function') {
    		window.onload = func;
    	} else {
    		window.onload = function() {
    function getElementsByClass(searchClass,node,tag) {
    	var classElements = new Array();
    	if (node == null) node = document;
    	if (tag == null) tag = '*';
    	var els = node.getElementsByTagName(tag);
    	var elsLen = els.length;
    	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    	for (i = 0, j = 0; i < elsLen; i++) {
    		if ( pattern.test(els[i].className) ) {
    			classElements[j] = els[i];
    	return classElements;
    //here's the meat of my script
    function enableEmails() {
    	var emails = getElementsByClass("email");
    	for (x in emails) {
    		theEmail = emails[x].innerHTML.replace(/(.*) at (.*) dot (.*)/g,"$1@$2.$3")
    		emails[x].innerHTML = "<a href=\"mailto:" + theEmail + "\">" + theEmail + "</a>";
    		<p>Ivana Tinkle<br>
    			<span class="email">ivana at domainname dot com</span></p>
    		<p>Amanda Hugnkiss<br>
    			<span class="email">amanda at domainname dot com</span></p>
    		<p>Oliver Clothesoff<br>
    			<span class="email">oliver at domainname dot com</span></p>
    Obviously if everyone did it, it could be worked around. Anyone have any reason why this wouldn't work?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Sydney, NSW, Australia
    25 Post(s)
    1 Thread(s)
    specifying at and dot as words is already a common technique and so some spambots at least probably already look for that. Can't see any other issues with it other than the usual one of requiring a separate email program which at least some of your visitors (eg. those in libraries and internet cafes) will not have available to them. No method using mailto: can ever be as effective (both for accessibility for real people and inaccessibility for spambots) as using a contact form.
    Stephen J Chapman, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts