button.addEventListener("click", () => setClipboard("<empty clipboard>"));
async function setClipboard(text) {
const type = "text/plain";
const clipboardItemData = {
[type]: text,
};
const clipboardItem = new ClipboardItem(clipboardItemData);
await navigator.clipboard.write([clipboardItem]);
}Clipboard: write() method / notebook
Clipboard: write() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<canvas id="canvas" width="100" height="100"></canvas>
<div id="target">Paste here.</div>