html5 - Pictures generated by html2canvas, checkbox and radio selected items cannot be screenshotted.
我想大声告诉你
我想大声告诉你 2017-05-16 13:32:24
0
1
1154

Generate a picture through html2canvas, and find that the checkbox selected item does not take a screenshot successfully.

<!DOCTYPE html>
<html>
<head>
    <title>
        html2canvas
    </title>
</head>
<body id="myPage"  onload="createImage()">
    <p style="height: 100px;width: 100px;background-color: blue">
        我是p
        性别:
        <input type="checkbox" name="sex">男
        <input type="checkbox" name="sex">女
    </p>
</body>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript">
    function createImage(){
        html2canvas(document.getElementById('myPage'),{
            allowTaint:true,
            height: 500
        }).then(function(canvas) {
           console.log(canvas);
           var aTag = document.createElement("a");
           aTag.innerHTML = "This is a test";
           aTag.setAttribute("style", "position:absolute; top:50%; z-index:999");
           aTag.setAttribute("href", canvas.toDataURL());
           aTag.setAttribute("download", "myPic.png");
           document.body.appendChild(aTag);
        });
    }
</script>
</html>

Page and production pictures:

我想大声告诉你
我想大声告诉你

reply all(1)
过去多啦不再A梦

It can be used, because the image is generated as soon as you enter the page, and subsequent clicks will have no effect, so you can do it this way.

<!DOCTYPE html>
<html>
<head>
<title>
    html2canvas
</title>
</head>
<body id="myPage">
<p style="height: 100px;width: 100px;background-color: blue">
    我是p
    性别:
    <input type="checkbox" onchange="createImage()" name="sex">男
    <input type="checkbox" onchange="createImage()" name="sex">女
</p>

</body>
<script type="text/javascript" src="https://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
<script type="text/javascript">
var aTag = document.createElement("a");
aTag.innerHTML = "This is a test";
aTag.setAttribute("style", "position:absolute; top:50%; z-index:999");
document.body.appendChild(aTag);
function createImage(){
    html2canvas(document.getElementById('myPage'),{
        allowTaint:true,
        height: 500
    }).then(function(canvas) {
       console.log(canvas);
       aTag.setAttribute("href", canvas.toDataURL());
       aTag.setAttribute("download", "myPic.png");   
    });
}
</script>
</html>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template