Created
March 27, 2020 17:36
-
-
Save origamid/772d5b7edc2b18cfa4f34107612520dd to your computer and use it in GitHub Desktop.
html 2 canvas 2 image download
This file contains 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
<div class="capture" contenteditable> | |
<p>Capture with right click</p> | |
</div> | |
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script> | |
<script> | |
const elementToSave = document.querySelector(".capture"); | |
// Download with right click | |
document.addEventListener("contextmenu", () => { | |
html2canvas(elementToSave).then(canvas => { | |
const a = document.createElement("a"); | |
a.href = canvas.toDataURL("image/jpeg"); | |
a.download = "image.jpeg"; | |
a.click(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment