Created
January 7, 2022 02:22
-
-
Save lotharthesavior/394f4066e45cf5649f1cb0994266ba0e to your computer and use it in GitHub Desktop.
Copy text to clipboard
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
const textContent = "Some Text to be copied"; | |
const textBlob = new Blob([textContent], { type: "text/plain" }); | |
const data = [new ClipboardItem({"text/plain": textBlob})]; | |
navigator.clipboard.write(data).then(function() { | |
console.log("Copied to clipboard successfully!"); | |
}, function() { | |
console.error("Unable to write to clipboard. :-("); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference:https://www.w3.org/TR/clipboard-apis/#clipboard-interface