-1

I try to copy a HTML and plain text set to clipboard, so that each editor can choose if he wants to paste text/html or text/plain.

I am using navigator.clipboard.write() (the async clipboard api).

Marian Rick
  • 3,350
  • 4
  • 31
  • 67

1 Answers1

2

The trick is quite simple, you can pass multiple blobs to one ClipboardItem:

const blob = new Blob([
    '<a href="https://stackoverflow.com/">goto stack</a>'
], { type: "text/html" });
const blobPlain = new Blob(['goto stack'], { type: "text/plain" });

navigator.clipboard.write([
    new ClipboardItem({
        [blob.type]: blob,
        [blobPlain.type]: blobPlain
    },),
])

Be aware this will not work in every browser (right now).

Colin
  • 1,112
  • 1
  • 16
  • 27