html2canvas没有在div中捕获外部图像

时间:2019-04-15 03:25:05

标签: javascript jquery html2canvas

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 个答案:

没有答案