Created
February 11, 2019 20:35
-
-
Save dotspencer/62f0f828e04931ed04c3918da2043b9a to your computer and use it in GitHub Desktop.
Simple copy from button click
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
document.querySelector('button').addEventListener('click', () => { | |
copyText('nice link'); | |
}); | |
function copyText(text) { | |
const input = document.createElement('input'); | |
input.value = text; | |
document.body.appendChild(input); | |
input.select(); | |
input.setSelectionRange(0, input.value.length); | |
document.execCommand('copy'); | |
document.body.removeChild(input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment