简体   繁体   中英

Latest version of HTML2CANVAS does not work in Chrome, Firefox

I have updated html2canvas from 0.4 to 1.0.0 and I used the function below to take a screenshot.

The function and html2canvas does not work and I got the error below.

How do I solve it?

icefaces-compat.js.jsf?ln=ice.compat&v=3_3_0_130416:1 2ms html2canvas: onrendered option is deprecated, html2canvas returns a Promise with the canvas as the value

function screenshotChrome() {
    var target = $(document.body);
    html2canvas(target, {
        useCORS: true,
        onrendered: function (canvas) {
            canvas.UniversalToBlob(function (blob) {
                    saveAs(blob, "aScreenshot.png");
                },
                "image/png", 1);
        }
    });
}

I'm not familiar with the library, but the error says that this version uses a Promise instead of using the onrendered callback option. Therefore, it is (probably) used like:

html2canvas(target, {
  useCORS: true
})
  .then(function (canvas) {
    canvas.UniversalToBlob(function (blob) {
      saveAs(blob, "aScreenshot.png");
    }, "image/png", 1);
  })
  .catch(function (err) { console.log(err); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM