Namespace: Interaction:obfuscatePrivateMailToLink

Interaction:obfuscatePrivateMailToLink

Methods

Augment a link element to hold an obfuscated private mailto link, to be able to contact people via their own mail address, without the need to openly write the address into the DOM permanently, in a way crawlers could identify easily.

The method takes all parts of the address as (hopefully) unidentifiable parameters and then applies them internally, to build an email string with mailto protocol dynamically on mouse or focus interaction in the link's href, offering normal link functionality from here on. If the interaction ends, the href is removed again immediately, so the link is only and exclusively readable and complete during user interaction.

You may set the link text yourself or set setAsContent to true, to let the function fill the link text with the completed address. Be aware, that this, although still being obfuscated, lowers the level of security for this solution.

Although most parameters are technically optional, this function still expects beforeAt and afterAtWithoutTld to be filled. While these parts are strictly necessary here: I'd always suggest to use all parts, since, the more of an address is written together, the easier the address can be parsed.

Parameters:
Name Type Attributes Default Description
link HTMLElement

the link to augment, has to be a node where we can set a "href" attribute

setAsContent Boolean <optional>
<nullable>
false

define if the address should be used as link text (still uses string obfuscation, but weaker against bot with JS execution)

tld String <optional>
<nullable>
''

the top level domain to use

afterAtWithoutTld String <optional>
<nullable>
''

the address part after the @ but before the tld

beforeAt String <optional>
<nullable>
''

the address part before the @

subject String <optional>
<nullable>
''

the subject the mail should have, if you want to preset this

body String <optional>
<nullable>
''

the body text the mail should have initially, if you want to preset this

ccTld String <optional>
<nullable>
''

the top level domain to use for the cc address

ccAfterAtWithoutTld String <optional>
<nullable>
''

the address part after the @ but before the tld for the cc address

ccBeforeAt String <optional>
<nullable>
''

the address part before the @ for the cc address

Source:
Throws:

error if beforeAt or afterAtWithoutTld are empty

Returns:
the augmented link
Type
HTMLElement
Example
obfuscatePrivateMailToLink(document.querySelector('a'), true, 'de', 'gmail', 'recipient', 'Hello there!', 'How are you these days?');