Skip to content

Instantly share code, notes, and snippets.

@Chalarangelo
Created February 20, 2018 10:44
Show Gist options
  • Save Chalarangelo/99e7cbee0de3c94f0077bb7555110767 to your computer and use it in GitHub Desktop.
Save Chalarangelo/99e7cbee0de3c94f0077bb7555110767 to your computer and use it in GitHub Desktop.
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment