Skip to content

Instantly share code, notes, and snippets.

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 math2001/c2d9f20f52fa6c07b2c63efe61976777 to your computer and use it in GitHub Desktop.
Save math2001/c2d9f20f52fa6c07b2c63efe61976777 to your computer and use it in GitHub Desktop.
var copyToClipboard = (function () {
const textarea = document.createElement('textarea')
// hide the textarea (since we can't use display: none, it's a bit long)
textarea.style.opacity = 0
textarea.style.width = 0
textarea.style.height = 0
textarea.style.position = 'absolute'
textarea.style.bottom = '-100%'
textarea.style.left = '-100%'
textarea.style.margin = 0
document.body.appendChild(textarea)
return function (text) {
textarea.value = text
textarea.select()
document.execCommand('copy')
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment