Skip to content

Instantly share code, notes, and snippets.

@fabiokandrade
Created February 7, 2018 15:35
Show Gist options
  • Save fabiokandrade/accee13370c6a12b83a7dfc5511520ee to your computer and use it in GitHub Desktop.
Save fabiokandrade/accee13370c6a12b83a7dfc5511520ee to your computer and use it in GitHub Desktop.
Copy via console.
function copyToClipboard(text) {
var textArea = document.createElement( "textarea" );
textArea.value = text;
document.body.appendChild( textArea );
textArea.select();
try {
var successful = document.execCommand( 'copy' );
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild( textArea );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment