Created
March 31, 2023 15:44
-
-
Save JoeGlines/5966064a8bd28a92b611619e53b87eb1 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
// Get the text you want to save to the clipboard | |
const textToCopy = "This text will be saved to the clipboard."; | |
// Create a new textarea element to hold the text | |
const textarea = document.createElement("textarea"); | |
textarea.value = textToCopy; | |
// Add the textarea element to the page | |
document.body.appendChild(textarea); | |
// Select the text in the textarea | |
textarea.select(); | |
// Copy the selected text to the clipboard | |
document.execCommand("copy"); | |
// Remove the textarea element from the page | |
document.body.removeChild(textarea); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment