Html2canvas Conflict In Mozila Firefox
I am using html2canvas libary. The code takes a div and save its content as png. It works fine with opera and chrome but while i run the code in firefox it does not save the div as
Solution 1:
Keep an
hidden
anchor element in theDOM
and update thehref
property of the element insideonrendered
handler.
$('#btn-Convert-Html2Image').click(function() {
html2canvas($('#html-content-holder'), {
onrendered: function(canvas) {
var a = $('#download').get(0);
a.href = canvas.toDataURL("image/png")
a.download = 'somefilename.png';
a.click();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.js"></script>
<div id="html-content-holder">
Div part to save as png
</div>
<input id="btn-Convert-Html2Image" type="button" value="Download" />
<a href="" id='download'></a>
Fiddle Demo
Solution 2:
You need to append the anchor element to the body in Firefox.
html2canvas($('#html-content-holder'), {
onrendered: function(canvas) {
var a = document.createElement('a');
a.href = canvas.toDataURL("image/png")
a.download = 'somefilename.png';
document.body.appendChild(a);
a.click();
}
});
Post a Comment for "Html2canvas Conflict In Mozila Firefox"