1

In my HTML page I have:

function convertCanvasToImage(canvas) {
        var image = new Image();
        image.src = canvas.toDataURL("image/png");
        return image;
    }

    function printImg() {
        html2canvas($('#chart_div').get(0)).then( function (canvas) {
            var image = convertCanvasToImage(canvas);
            var htmlToPrint = image.outerHTML ;
            var newWin = window.open("");
            newWin.document.write(htmlToPrint);
            newWin.print();
            newWin.close();
        });
    }

When I call the function printImg I get this error:

TypeError: newWin is null

What is missing?

senior
  • 2,196
  • 6
  • 36
  • 54
  • 4
    Your browser is blocking the created window. You can only call `window.open()` _synchronously_ from a user event such as a `click` event listener. – Patrick Roberts Sep 18 '19 at 15:55

0 Answers0