Obfuscating Emails Revisited
The outcome of my last entry about obfuscating email addresses is the HTML → Encrypt Selection (ROT13) command which replaces the current selection with JavaScript to output it (with the actual markup stored in ROT13).
Since most of my pages are already preprocessed, I decided to turn it into a general filter that works on a full HTML page. It replaces all document nodes (which contain an email address) with the corresponding JavaScript.
Since it has given me much joy to once again be able to write plain email addresses in my pages (without worrying about spam harvesters) I figured I should share :) But do double-check that the result you get from the filter is actually what you expect — the parser used is written for (my) valid HTML pages with potential script tags (such as <% … %>
and <?php … ?>
).
By replacing the full document node with a <script> … </script>
-construct it should keep the resulting page as well-formed. Though the filter inserts a <noscript>
-tag to improve usability (for clients without JavaScript) but the <noscript>
-tag is a block-level tag, so this will generally make the page non-valid. If you want a validating page then you can remove the <noscript>
stuff at line 119.
I have pondered a few ways to keep the page as valid and still insert a <noscript>
-tag, but I think the best approach would be to instead have the <noscript>
-content be the default content, and then use JavaScript to replace that (so avoid using the <noscript>
-tag). Ideally the fallback content should be a human-decodable version of the email address.
If anyone ports the filter to PHP please let me know, as I would love to turn it into a WordPress plug-in.