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 ).
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
},),
])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.