html2canvas 并下载

function claaaa(event) {

    html2canvas(document.querySelector("body")).then(canvas => {
           var oA = document.createElement('a');
        oA.download = 'shuty';  // 设置下载的文件名
        var url = canvas.toDataURL("image/png"); // canvas转png(base64)
        oA.href = url; // a标签的url对应图片base64
        document.body.appendChild(oA);
        oA.click();
        document.body.removeChild(oA);    
});


};


$(document).on('click', '.demo canvas', function () { 
    var data = $(this)[0].toDataURL('image/png');
    $.post('/tool/upload', {image: data}, function(data, textStatus, xhr) {
        var dlLink = document.createElement('a');
        dlLink.href = '/tool/download/'+data;
        document.body.appendChild(dlLink);
        dlLink.click();
        document.body.removeChild(dlLink);        
    });
    

});

赞(0) 打赏
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

    暂无评论...