Skip to content

Instantly share code, notes, and snippets.

@markhunte
Forked from origamid/html2img.html
Created September 21, 2023 17:40
Show Gist options
  • Select an option

  • Save markhunte/9ee9193c2919d1adee807ecc5854be20 to your computer and use it in GitHub Desktop.

Select an option

Save markhunte/9ee9193c2919d1adee807ecc5854be20 to your computer and use it in GitHub Desktop.

Revisions

  1. @origamid origamid created this gist Mar 27, 2020.
    17 changes: 17 additions & 0 deletions html2img.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <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>