Last active
July 22, 2020 05:09
-
-
Save Richienb/d5cdaa63c90dd678bacac0939c561066 to your computer and use it in GitHub Desktop.
Synchronously copy text to the clipboard in browsers
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 copyElement = document.createElement("textarea") | |
document.querySelector("body").appendChild(copyElement) | |
copyElement.textContent = text | |
copyElement.select() | |
document.execCommand("copy") | |
document.querySelector("body").removeChild(copyElement) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment