[英]html2canvas not downloading the image with firefox
i'm using html2canvas , and i try to download the div as picture 我正在使用html2canvas,我尝试将div下载为图片
it's work fine on google chrome but in fire fox it's not 在谷歌浏览器上工作正常,但在狐狸浏览器中却不是
this is my code 这是我的代码
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.js"></script>
<script type="text/javascript">
$('#save_image_locally').click(function(){
html2canvas([document.getElementById('#mydiv')],
{
onrendered: function (canvas) {
var a = document.createElement('a');
a.href = canvas.toDataURL('image/png');
a.download = 'somefilename.jpg';
a.click();
}
});
});
</script>
This is a working example: https://jsfiddle.net/obkm27v5/4/ 这是一个工作示例: https : //jsfiddle.net/obkm27v5/4/
$(document).ready(function() {
$('#save_image_locally').click(function(){
html2canvas([document.getElementById('mydiv')],
{
onrendered: function (canvas) {
var a = $("<a>").attr("href", canvas.toDataURL('image/png'))
.attr("download", "output.png")
.appendTo("body");
a[0].click();
a.remove();
}
});
});
You have to add the anchor tag to the DOM before clicking. 单击之前,必须将锚标记添加到DOM。 There was also a wrong id in your canvas selector 您的画布选择器中还有一个错误的ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.