Skip to content

Instantly share code, notes, and snippets.

@kitten
Last active March 4, 2016 17:56
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 kitten/71664b44342d61fd277a to your computer and use it in GitHub Desktop.
Save kitten/71664b44342d61fd277a to your computer and use it in GitHub Desktop.
Copy text to the user's clipboard
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