I have to generate a url to the clipboard when user click the button. The question is, I have no idea how can I make this url clickable when I paste it into email. The result turns out to plain text. And I am using ReactJs as my frontend framework. I have tried using Clipboard.writeText(), but it not works. I also tried to paste html code to email, but all I get is plain text. I have seen other website implemented this function, but I really don't know how to do this.
You can copy a string to the clipboard by turning on the following:
navigator.clipboard.writeText('text');full example
const [text, setText] = useState(""); const handleChange = (e) => { setText(e.target.value); }; const handleCopy = () => { navigator.clipboard.writeText(text); }; return ( <div> <input type="text" value={text} onChange={handleChange} /> <button onClick={handleCopy}>Copy</button> </div> );If that doesn't work, I'd check the console for other errors.
I think I've solved this myself. Simply put the html code as type [text/html] in the clipboard API and it can be copied as seen on a web page.