Created
October 12, 2021 11:05
-
-
Save charisTheo/242e4d95a485ea4cfba5e456888b5694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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