DEV Community

irishgeoff22
irishgeoff22

Posted on • Edited on

obfuscate email address

Email address obfuscation means hiding or disguising an email address on a web page to prevent it from being easily collected by spammers or web scrapers. This can involve techniques like character encoding, JavaScript generation, using images, or contact forms to make it less accessible to automated data collection.

<!DOCTYPE html>
<html>
<head>
    <script>
        function encodeEmail() {
            const linkText = document.getElementById("linktext").value;
            const linkEmail = "mailto:" + document.getElementById("emailaddress").value.toLowerCase();
            const encodedLink = linkEmail.split("").map(char => `&#${char.charCodeAt(0)};`).join("");
            const encodedText = linkText.split("").map(char => `&#${char.charCodeAt(0)};`).join("");

            if (linkText === "") {
                alert("You must enter a name to show on the link.");
                document.getElementById("linktext").focus();
            } else if (linkEmail === "mailto:") {
                alert("You must enter an email address.");
                document.getElementById("emailaddress").focus();
            } else {
                document.getElementById("obfuscated").value = `<a href="${encodedLink}">${encodedText}</a>`;
            }
        }
    </script>
</head>
<body>
    <div>&nbsp;<br class="clear" /></div>
    <table border="0" cellspacing="0" cellpadding="5" width="90%">
        <tr>
            <td width="120" valign="top">
                <script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
            </td>
            <td valign="top">
                <img src="images/trans.gif" alt=" " width="1" height="1" align="right" />
                <h2>Protect your e-mail identity from spam:</h2>
                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="3">
                    <tr>
                        <td valign="top">
                            <form>
                                <p>Enter the name to show on the link:</p>
                                <input type="text" id="linktext" size="40" />
                                <p>Enter the e-mail address:</p>
                                <input type="text" id="emailaddress" size="40" />
                                <p>Click the ENCODE button below to encode the above information.</p>
                                <p align="center">
                                    <input type="button" value="ENCODE" onclick="encodeEmail()" />
                                </p>
                                <p>Below is your encoded e-mail link:</p>
                                <textarea id="obfuscated" rows="8" cols="90"></textarea>
                                <p align="center">
                                    <input type="reset" value="Clear form to start over" />
                                </p>
                            </form>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

obfuscate email by hiding your email behind a captcha https://veilmail.io

Top comments (0)