javascript - Google Map is not displayed when using html2canvas - Stack Overflow

I have done the screenshot button that have to make the screenshot of all body.But on this screenshot g

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:

look here for screenshot

can you please tell me whats wrong?

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:

look here for screenshot

can you please tell me whats wrong?

Share Improve this question edited Sep 18, 2017 at 14:08 mikemaccana 124k110 gold badges432 silver badges534 bronze badges asked Sep 18, 2017 at 14:02 Olena ChabanOlena Chaban 1211 gold badge2 silver badges7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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();
        }
    });
}
    var fin = document.getElementById("map");

    html2canvas(fin, {
    useCORS: true,
    onrendered: function(canvas) {
        var dataUrl= canvas.toDataURL("image/png");
        $('#map_image').attr('src',dataUrl).show();
    }
  });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745199745a4616266.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信