Created
August 30, 2017 22:52
-
-
Save nashingofteeth/f2721301767b4e27cffcad1296cf3a74 to your computer and use it in GitHub Desktop.
copy data to clipboard without copy event
This file contains 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
function copyText (text) { | |
const element = document.createElement('textarea'); | |
element.value = text; | |
document.body.appendChild(element); | |
element.focus(); | |
element.setSelectionRange(0, element.value.length); | |
document.execCommand('copy'); | |
document.body.removeChild(element); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment