Actions

Difference between revisions of "How to cloak email addresses"

From Joomla! Documentation

m
m (Non-clickable email address: fixing)
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{version/tutor|2.5,3.x}}{{RightTOC}}
 
It is good practice to make sure that email addresses that appear on your website are obfuscated, or 'cloaked'. This means that they are readable by people, but not by bots that harvest email addresses from websites for spamming purposes.  Email addresses are made un-readable to these bots by 'assembling' them via JavaScript when the page is loaded. Although they appear on your screen as a readable e-mail address, the actual email address itself never appears in the code.
 
It is good practice to make sure that email addresses that appear on your website are obfuscated, or 'cloaked'. This means that they are readable by people, but not by bots that harvest email addresses from websites for spamming purposes.  Email addresses are made un-readable to these bots by 'assembling' them via JavaScript when the page is loaded. Although they appear on your screen as a readable e-mail address, the actual email address itself never appears in the code.
  
 
Joomla has inbuilt email cloaking functionality that can be called within a component or module template, through the JHtml Class.  To call this cloaking routine in your component, use the following syntax:
 
Joomla has inbuilt email cloaking functionality that can be called within a component or module template, through the JHtml Class.  To call this cloaking routine in your component, use the following syntax:
 
+
==Clickable link to email address==
 +
This will create a mailto link, that people can click on to email that email address, that will be hidden from bots in complicated javascript.
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
 
echo JHtml::_('email.cloak', 'demo@example.com');
 
echo JHtml::_('email.cloak', 'demo@example.com');
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Which will display [mailto:demo@example.com demo@exmaple.com]
+
Which will display  
  
This will create a mailto link, that people can click on to email that email address, that will be hidden from bots in complicated javascript.
+
:<code><span style="color:#0645ad">demo@example.com</span></code>
  
 +
==Non-clickable email address==
 
If you want to not have a mailto link, and just have an email address displayed that is not a hyper link, use the following syntax:
 
If you want to not have a mailto link, and just have an email address displayed that is not a hyper link, use the following syntax:
  
Line 17: Line 20:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
This will simply display '''demo@example.com'''.
+
This will simply display the following output:
 +
:<code>'''demo@example.com'''</code>
  
 +
==Display different email address than the hyperlinked email address==
 
If you would like to have a different email address displayed from the one that is actually linked to, you use the following syntax:
 
If you would like to have a different email address displayed from the one that is actually linked to, you use the following syntax:
  
Line 25: Line 30:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
This will display something like [mailto:website_catchall@example.com demo@example.com] but obfuscated by JavaScript.
+
This will display something like  
 +
:<code><span style="color:#0645ad">demo@example.com</span></code>
 +
but the actual email hyperlink going to
 +
:<code><span style="color:#0645ad"><nowiki>mailto:website_catchall@example.com</nowiki></span></code>
 +
and obfuscated by JavaScript.
  
 +
==Display phrase, hyperlinked to email address==
 
And if you would like a different phrase other than an email address displayed as a mailto hyper-link, use this syntax:
 
And if you would like a different phrase other than an email address displayed as a mailto hyper-link, use this syntax:
  
Line 33: Line 43:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
This will display something like [mailto:demo@example.com click here to email me] but again obfuscated by JavaScript.
+
This will display something like  
 +
:<code><span style="color:#0645ad">click here to email me</span></code>
 +
but the actual email hyperlink going to
 +
:<code><span style="color:#0645ad"><nowiki>mailto:website_catchall@example.com</nowiki></span></code>
 +
and obfuscated by JavaScript.
  
 
[[Category:Development]]
 
[[Category:Development]]
 +
[[Category:Tips and tricks]]

Latest revision as of 11:50, 6 October 2013

Contents

It is good practice to make sure that email addresses that appear on your website are obfuscated, or 'cloaked'. This means that they are readable by people, but not by bots that harvest email addresses from websites for spamming purposes. Email addresses are made un-readable to these bots by 'assembling' them via JavaScript when the page is loaded. Although they appear on your screen as a readable e-mail address, the actual email address itself never appears in the code.

Joomla has inbuilt email cloaking functionality that can be called within a component or module template, through the JHtml Class. To call this cloaking routine in your component, use the following syntax:

Clickable link to email address

This will create a mailto link, that people can click on to email that email address, that will be hidden from bots in complicated javascript.

echo JHtml::_('email.cloak', 'demo@example.com');

Which will display

demo@example.com

Non-clickable email address

If you want to not have a mailto link, and just have an email address displayed that is not a hyper link, use the following syntax:

echo JHtml::_('email.cloak', 'demo@example.com', 0);

This will simply display the following output:

demo@example.com

Display different email address than the hyperlinked email address

If you would like to have a different email address displayed from the one that is actually linked to, you use the following syntax:

echo JHtml::_('email.cloak', 'website_catchall@example.com', 1, 'demo@exmaple.com');

This will display something like

demo@example.com

but the actual email hyperlink going to

mailto:website_catchall@example.com

and obfuscated by JavaScript.

Display phrase, hyperlinked to email address

And if you would like a different phrase other than an email address displayed as a mailto hyper-link, use this syntax:

echo JHtml::_('email.cloak', 'demo@exmaple.com', 1, 'click here to email me', 0);

This will display something like

click here to email me

but the actual email hyperlink going to

mailto:website_catchall@example.com

and obfuscated by JavaScript.