Home  >  Q&A  >  body text

javascript - html2canvas, realizing screenshots and image cross-domain issues.

  1. Cross-domain issues are also reported when using local images to generate screenshots.

<p id="navp">
    <a onClick="testFun();">
        <p class="title-msg">美的国际支持部美国加利福尼亚州综合统计报表</p>
        <p>
            <img id="imgTest" src="images/worldMap.png">
        </p>
    </a>
</p>
html2canvas(document.getElementById('navp'),{
    allowTaint:true,
    height: 500
}).then(function(canvas) {
    var aTag = document.createElement("a");
    aTag.innerHTML = "This is a test";
    aTag.setAttribute("href", canvas.toDataURL());
    aTag.setAttribute("download", "myPic.png");
    document.body.appendChild(aTag);
});

给我你的怀抱给我你的怀抱2712 days ago835

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:46:33

    http://stackoverflow.com/ques...

    To use canvas to read images, it is best to start a local web service to start this page (otherwise it is considered cross-domain). Don't just open the local html file with the browser.

    reply
    0
  • Cancelreply