Created
February 20, 2016 17:30
-
-
Save imjasonh/c6028a9a3a3157724f7e to your computer and use it in GitHub Desktop.
Code snippet to copy text to clipboard (doesn't work from a Chrome extension background.js)
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
var text = 'Hello world'; | |
var buffer = document.createElement('buffer'); | |
document.body.appendChild(buffer); | |
buffer.value = text; | |
buffer.focus(); | |
buffer.selectionStart = 0; | |
buffer.selectionEnd = buffer.value.length; | |
if (!document.execCommand('copy')) { | |
console.log('Couldn\'t copy from buffer'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment