【问题标题】:How can i get this rendered canvas?我怎样才能得到这个渲染的画布?
【发布时间】:2019-12-05 17:36:36
【问题描述】:

当我在 Firefox 控制台中运行此代码时,我得到了未定义的返回值并打开了一个空白页

    let m=$.getScript("https://html2canvas.hertzen.com/dist/html2canvas.js", function() {
html2canvas(document.querySelector("body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > img"), {
            onrendered: function(canvas) {
                 var myImage = canvas.toDataURL("image/png");
        return myImage;
               },
                       allowTaint: true,
                    taintTest: false
         });
         }); 


m.then((value) => {
    console.log(value);
    window.open(value);
});

但 Firefox 控制台显示有一个带有我需要的图像的渲染画布

check screenshot of the firefox console

请问我怎样才能得到这张图片?

谢谢

【问题讨论】:

    标签: javascript jquery promise console.log html2canvas


    【解决方案1】:

    实际上是一行

    m.then((value) => {
       console.log(value);  //this line
       window.open(value);
    });
    

    它返回画布以便将画布转换为您需要的图像canvas.toDataUrl 即

    let image = canvas.toDataUrl("image/png");
    

    然后

    window.open(image);
    

    在新标签中显示

    您还可以在 iframe 中的新窗口中显示图像,即

    var win = window.open();
    win.document.write('<iframe src="' + image + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
    

    【讨论】:

      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多