How to put image to clipboard using Javascript (in handler of copy
event) as if it would by done by right click on image in browser and selecting "Copy Image" from context menu.
This script shows details of clipboard content. For copied image it prints:
DataTransfer { dropEffect: "none", effectAllowed: "uninitialized", items: DataTransferItemList[2], types: Array[2], files: FileList[1], mozItemCount: 1, mozCursor: "auto", mozUserCancelled: false, mozSourceNode: null }
DataTransferItem { kind: "string", type: "text/html" }
DataTransferItem { kind: "file", type: "image/png" }
Array [ "text/html", "Files" ]
File { name: "image.png", lastModified: 1504122845696, lastModifiedDate: Date 2017-08-30T19:54:05.696Z, webkitRelativePath: "", size: 385273, type: "image/png" }
So the question can be probably reformulated - how to attach a file to clipboardData
in copy
event handler function?
document.addEventListener('copy', (event) => {
// event.clipboardData.?
// maybe event.clipboardData.setData(?)
})