div to png

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
        
        <script>
            function handleDownload() {
            //const divElement = document.getElementById("myDiv");
            const divElement = this;
            const divId = divElement.id || "download"; // Fallback to 'download' if there's no id
            html2canvas(divElement, { backgroundColor: null }).then((canvas) => {
                const imgData = canvas.toDataURL("image/png");
                const link = document.createElement("a");
                link.href = imgData;
                link.download = `${divId}.png`;
                link.click();
            });
            }
        </script>
        <style>
            .round_box {
                border-radius: 10px;
                font-size: 15px;
                font-family: nanumgothic;
                background-color: #111;
                color: white;
                padding: 10px;
                display: inline-block;
                cursor: pointer;
            }
        </style>
        <title>Download Div as PNG</title>
    </head>

    <body>
    <div id="box01" class="round_box" onclick="handleDownload.call(this)">페놀프탈레인 용액</div>
    </body>
</html>