Last active
March 8, 2021 16:33
-
-
Save manuelvegadev/aa36611423dd9d648f92b080f1402586 to your computer and use it in GitHub Desktop.
Copy to clipboard with pure JavaScript
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
async function copyToClipboard({text, message='Copied to clipboard', mdIcon = 'check'}) { | |
let tempInput = document.createElement('input') | |
tempInput.value = text | |
document.body.appendChild(tempInput) | |
tempInput.select(); | |
document.execCommand('copy') | |
document.body.removeChild(tempInput) | |
await createSnackbar({ | |
message: message, | |
mdIcon: mdIcon | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment