email-link.js
v1.1.0
Published
A tiny utility to hide email addresses from spammers
Readme
email-link.js - A tiny utility to hide e-mail addresses from spammers
What is it
This is just a tiny utility library to hide plain-text e-mail addresses from your website.
Usage
import {enableEmailLinks} from "email-link.js";
window.addEventListener("DOMContentLoaded", () => enableEmailLinks());In order for the library to find the e-mail links, they must have a
data-email-address attribute. If the attribute is empty, the link text
must contain the e-mail address with the @ sign replaced by a single space.
Otherwise the e-mail address must be given as the attribute value:
<a data-email-address>alice example.com</a>
<a data-email-address="bob example.com">Send a message to Bob</a>Optional parameters
Optionally the function enableEmailLinks takes two parameters. But they are only
needed if you want to override which links get processed and how the data attribute
with the e-mail address is called:
- {String} selector: CSS selector string to select all elements which link to an e-mail address. Default: "a[data-email-address]"
- {String} dataAttributeName: Name of the data attribute, which contains the e-mail address if the link text doesn't. Default: "email-address"
Example for another selector:
enableEmailLinks("a.hasEmail")finds all <a class="hasEmail">
Example for another selector and data attribute:
enableEmailLinks("#footer a.email", "mailto")expects all links to be inside
an element with the ID footer and to be of the following form:
<a class="email" data-mailto="chris example.com">Chris Doe</a>Copyright
email-link.js: https://www.github.com/DennisSchulmeister/email-link.js © 2018 – 2026 Dennis Schulmeister-Zimolong [email protected]
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
