Reputation: 121
I have done the screenshot button that have to make the screenshot of all body.
But on this screenshot google map is not dispayed. I used html2canvas library to do this. Here is the code :
HTML:
<button type="button" class="btn btn-default btn-sm" id = 'screenShotBtn' onclick="takeScreenShot()">
JAVASCRIPT :
var takeScreenShot = function() {
var screenshot = {};
html2canvas(document.getElementById('screenAll'), {
onrendered: function (canvas) {
var tempcanvas=document.createElement('canvas');
tempcanvas.width=1350;
tempcanvas.height=700;
var context=tempcanvas.getContext('2d');
context.drawImage(canvas,0,0,1350,700,0,0,1350,700);
var link=document.createElement("a");
link.href=tempcanvas.toDataURL('image/jpg'); //function blocks CORS
link.download = 'screenshot.jpg';
link.click();
}
});
And here is what I have when make the screenshot:
can you please tell me whats wrong?
Upvotes: 4
Views: 4460
Reputation: 31
var fin = document.getElementById("map");
html2canvas(fin, {
useCORS: true,
onrendered: function(canvas) {
var dataUrl= canvas.toDataURL("image/png");
$('#map_image').attr('src',dataUrl).show();
}
});
Upvotes: 2
Reputation: 121
I added those properties to code and it works:
var takeScreenShot = function() {
var screenshot = {};
html2canvas(document.getElementById('map'), {
useCORS: true,
optimized: false,
allowTaint: false,
onrendered: function (canvas) {
var tempcanvas=document.createElement('canvas');
tempcanvas.width=1350;
tempcanvas.height=700;
var context=tempcanvas.getContext('2d');
context.drawImage(canvas,0,0,1350,700,0,0,1350,700);
var link=document.createElement("a");
link.href=tempcanvas.toDataURL('image/jpg'); //function blocks CORS
link.download = 'screenshot.jpg';
link.click();
}
});
}
Upvotes: 3