Last active
March 4, 2016 17:56
-
-
Save kitten/71664b44342d61fd277a to your computer and use it in GitHub Desktop.
Copy text to the user's 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
var copy = (function() { | |
var input = document.createElement('input'); | |
input.style.opacity = '0'; | |
input.style.position = 'fixed'; | |
input.style.top = '-1000%'; | |
document.body.appendChild(input); | |
return function copy(text) { | |
input.value = text; | |
input.select(); | |
try { | |
document.execCommand('copy'); | |
} catch(err) { } | |
input.blur(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment