Created
February 7, 2018 15:35
-
-
Save fabiokandrade/accee13370c6a12b83a7dfc5511520ee to your computer and use it in GitHub Desktop.
Copy via console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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