-
-
Save ioniacob/eecb7330c9801ca91934d4e2dd818fa3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!-- | |
Via: http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript | |
--> | |
<textarea class="js-copytextarea">Hello I'm some text</textarea> | |
<button class="js-textareacopybtn">Copy Text</button> | |
<script> | |
var copyTextareaBtn = document.querySelector('.js-textareacopybtn'); | |
copyTextareaBtn.addEventListener('click', function(event) { | |
var copyTextarea = document.querySelector('.js-copytextarea'); | |
copyTextarea.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'); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment