Created
December 31, 2018 08:45
-
-
Save hizo/5c9169450140ba7b5f92f47021534ed2 to your computer and use it in GitHub Desktop.
Vanilla copy to clipboard
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
const copy = content => { | |
const textArea = document.createElement('textarea') | |
textArea.style.maxHeight = '0px' | |
textArea.style.height = '0px' | |
textArea.style.opacity = '0' | |
textArea.value = content | |
document.body.appendChild(textArea) | |
textArea.select() | |
try { | |
window.document.execCommand('copy') | |
} catch (err) { | |
console.error('Failed to copy.') | |
} | |
document.body.removeChild(textArea) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment