TIL Copy Text to Clipboard
POSTED ON:
TAGS: javascript
I made an app that generates a clean piece of data for the end-user.
The user then copies that data, and pastes it somewhere else.
This trick lets you do that:
const copyTextToClipboard = async (text) => {
await navigator.clipboard.writeText(text)
}
Note that this function is asynchronous since the writeText function returns a Promise.
REFERENCE:
via https://javascript.plainenglish.io/15-helpful-javascript-one-liners-946e1d1a1653
Related TILs
Tagged: javascript