Created
October 1, 2015 18:14
-
-
Save mdamien/a0f2bd91750a2d45c8ab to your computer and use it in GitHub Desktop.
Copy to clipboard using native js api
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 copy_to_clipboard(text) { | |
var el = document.createElement('textarea'); | |
el.style.position = 'absolute'; | |
el.style.left = '-9999px'; | |
el.setAttribute('readonly', ''); | |
el.value = text; | |
document.body.appendChild(el); | |
el.select(); | |
var success = document.execCommand('copy'); | |
document.body.removeChild(el); | |
return success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment