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;
}
}
});
});
});
});