Skip to content

Instantly share code, notes, and snippets.

@nashingofteeth
Created August 30, 2017 22:52
Show Gist options
  • Save nashingofteeth/f2721301767b4e27cffcad1296cf3a74 to your computer and use it in GitHub Desktop.
Save nashingofteeth/f2721301767b4e27cffcad1296cf3a74 to your computer and use it in GitHub Desktop.
copy data to clipboard without copy event
function copyText (text) {
const element = document.createElement('textarea');
element.value = text;
document.body.appendChild(element);
element.focus();
element.setSelectionRange(0, element.value.length);
document.execCommand('copy');
document.body.removeChild(element);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment