I wrote this perl script years ago when I needed to include my email address on a webpage, but also conceal it from spam bots and spiders.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/usr/bin/perl -w # /usr/local/bin/esc-mailto.pl # Conceal email address with javaScript. # by Jean-Sebastien Morisset (https://surniaulula.com/) use strict; my ($email, $text) = @ARGV; $text = $email if (!$text); if ($email && $text) { my $mailto = "<a href=\"mailto:$email\" class=\"esc-mailto\">$text</a>"; $mailto =~ s/(.)/sprintf("%%%x", ord($1))/ge; print "<script language=\"JavaScript\">document.write(unescape(\"$mailto\"))</script>\n"; } else { print "syntax: $0 {email_address} [optional_link_text]\n"; exit 1; } exit 0; |
Download the esc-mailto.pl script.
Cut-and-paste the resulting javascript output to any webpage. The client’s browser will execute the JavaScript and display the resulting HTML text. For example, here’s the output for esc-mailto.pl user@domain.com
.
1 2 3 |
<script type="text/javascript">document.write(unescape("%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%75%73%65%72%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%20%63%6c%61%73%73%3d%22%65%73%63%2d%6d%61%69%6c%74%6f%22%3e%75%73%65%72%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e"))</script> |