Skip to content

Instantly share code, notes, and snippets.

@charisTheo
Created October 12, 2021 11:05
Show Gist options
  • Save charisTheo/242e4d95a485ea4cfba5e456888b5694 to your computer and use it in GitHub Desktop.
Save charisTheo/242e4d95a485ea4cfba5e456888b5694 to your computer and use it in GitHub Desktop.
document.querySelector('.copy-button').addEventListener('click', async () => {
const src = document.querySelector('.image-to-copy').src
try {
const blob = await getImageBlobFromUrl(src)
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
])
alert('Image copied to clipboard!')
} catch (err) {
console.error(err.name, err.message);
alert('There was an error while copying image to clipboard :/')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment