html2canvas不能在div内捕获外部图像

时间:2019-04-14 05:35:12

标签: java jquery base64 html2canvas imgur

html2canvas不能在div中捕获外部图像。我发现某个地方allowTaint: true可以解决问题。但仍然得到空白图片。请帮忙

代码

$(document).ready(function() {

$("#capture").click(function(){

    html2canvas($('#preview-container').get(0),{ allowTaint: true }).then( function (canvas) {
   // console.log(canvas.toDataURL());
   dataURL= canvas.toDataURL('image/jpeg', 0.9).split(',')[1];

        $.ajax({
        url: 'https://api.imgur.com/3/image',
        type: 'post',
        headers: {
            Authorization: 'Client-ID ***********'
        },
        data: {
            image: dataURL
        },
        dataType: 'json',
        error:function(response){

        console.log(response);

        },
        success: function(response) {
            if(response.success) {
                alert(response.data.link);
                window.location = response.data.link;

            }
        }
    });
 });

   });
 });

0 个答案:

没有答案