Created
October 5, 2020 02:17
-
-
Save RuanAragao/57a3905726127a25ceaa8d0c428082fe to your computer and use it in GitHub Desktop.
Copy to clipboard function Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const copyToClipboard = (str: string) => { | |
const el = document.createElement('textarea'); | |
el.value = str; | |
el.setAttribute('readonly', ''); | |
el.style.position = 'absolute'; | |
el.style.left = '-9999px'; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment