Skip to content

Instantly share code, notes, and snippets.

@mbixby
Created January 22, 2024 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbixby/ea0b044c5552b8df439d3b724659458c to your computer and use it in GitHub Desktop.
Save mbixby/ea0b044c5552b8df439d3b724659458c to your computer and use it in GitHub Desktop.
Rich text clipboard
const clipboardItem = new ClipboardItem({
"text/plain": new Blob(
['https://example.com'],
{ type: "text/plain" }
),
"text/html": new Blob(
['<a href="https://example.com">Example link</a>'],
{ type: "text/html" }
),
"application/rtf": new Blob(
['{\field{\*\fldinst HYPERLINK "https://example.com"}{\fldrslt Example link}}'],
{ type: "text/html" }
),
});
navigator.clipboard.write([clipboardItem])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment