Paste images from clipboard
A JavaScript script to paste images from Clipboard.
Inspired on Our Code World script example.
Mode | Implemented |
---|---|
blob |
Yes |
base64 |
Yes |
Use
Create a .js
file and copy the content from script.js
to your project.
In your HTML page, import the script:
<script src="script.js" type="text/javascript">
CLIPBOARD.init('blob')
</script>
For Blob
mode, you have create a <canvas>
:
<canvas id="clipboard-canvas"></canvas>
Listener
Use pasteFromClipboard
custom event to receive images pasted from clipboard.
document.addEventListener('pasteFromClipboard', e => {
console.log('Image received', e.detail)
})
The listener returns:
{
"bubbles": false,
"cancelBubble": false,
...
"detail": { ... }, // <-- returns pasted image
}