Skip to content

Instantly share code, notes, and snippets.

@mdamien
Created October 1, 2015 18:14
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 mdamien/a0f2bd91750a2d45c8ab to your computer and use it in GitHub Desktop.
Save mdamien/a0f2bd91750a2d45c8ab to your computer and use it in GitHub Desktop.
Copy to clipboard using native js api
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