Skip to content

Instantly share code, notes, and snippets.

@hizo
Created December 31, 2018 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hizo/5c9169450140ba7b5f92f47021534ed2 to your computer and use it in GitHub Desktop.
Save hizo/5c9169450140ba7b5f92f47021534ed2 to your computer and use it in GitHub Desktop.
Vanilla copy to clipboard
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