JSFiddle - React, Tailwind, and code Playground

by Sayantan Das

HTML

<a href="mailto:[email protected]">Link text</a>

JavaScript

document.addEventListener('copy', (event) => {

    // Get the selected text

    let selectedText = window.getSelection().toString();

    

    // Modify the selected text if it contains "mailto:"

    if (selectedText.startsWith('mailto:')) {

        selectedText = selectedText.replace(/^mailto:/, '');

        

        // Set the modified text to the clipboard

        event.clipboardData.setData('text/plain', selectedText);

        

        // Prevent the default copy action

        event.preventDefault();

    }

});