无法将html2canvas生成的图像共享给whatsapp api
我试图使用html2canvas将html转换为图像,并且有一个base64图像字符串,该字符串是通过canvas.toDataURL('image / png')生成的。现在,我希望将此图像以https://api.whatsapp.com/send?text=image.png的形式通过whatsapp共享。但是我的图像没有通过API传递
function share_image()
{
var data ='';
html2canvas([document.getElementById('main_div')], {
onrendered: function(canvas) {
data = canvas.toDataURL('image/png');
var whatsapp_url = 'https://api.whatsapp.com/send?text='+encodeURIComponent(data);
window.location.href = whatsapp_url;
},
});
}
<div id="main_div">
<span onclick="share_image()">
</span>
</div>
当我单击范围时,我想生成div的图像并通过网络通过whatsapp共享它