Skip to content

Instantly share code, notes, and snippets.

@lotharthesavior
Created January 7, 2022 02:22
Show Gist options
  • Save lotharthesavior/394f4066e45cf5649f1cb0994266ba0e to your computer and use it in GitHub Desktop.
Save lotharthesavior/394f4066e45cf5649f1cb0994266ba0e to your computer and use it in GitHub Desktop.
Copy text to clipboard
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. :-(");
});
@lotharthesavior
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment