Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “打印窗口”不会在chrome最新版本中打印整个页面_Javascript_Html_Google Chrome_Printing - Fatal编程技术网

Javascript “打印窗口”不会在chrome最新版本中打印整个页面

Javascript “打印窗口”不会在chrome最新版本中打印整个页面,javascript,html,google-chrome,printing,Javascript,Html,Google Chrome,Printing,我正在开发一个使用HTML5画布的打印工具。通过打开一个新窗口,将页面画布作为图像写入新窗口文档,然后最终打印窗口文档。作为测试,我尝试在chrome最新版本(46.0.2490.71版)中打印页面(大于100页),但它不会打印整个页面。在chrome打印预览窗口中,只显示部分页面,就像我们打印110页文档一样,这意味着它只显示24或38页(随机显示页面)。但整个页面都添加到新创建的窗口中进行打印。 我使用下面的代码来打印页面 var _printWindow = window.open('')

我正在开发一个使用HTML5画布的打印工具。通过打开一个新窗口,将页面画布作为图像写入新窗口文档,然后最终打印窗口文档。作为测试,我尝试在chrome最新版本(46.0.2490.71版)中打印页面(大于100页),但它不会打印整个页面。在chrome打印预览窗口中,只显示部分页面,就像我们打印110页文档一样,这意味着它只显示24或38页(随机显示页面)。但整个页面都添加到新创建的窗口中进行打印。 我使用下面的代码来打印页面

var _printWindow = window.open('');
_printWindow.document.write('<html><BODY>');
_printWindow.document.write('<center>');
for (var i = 1; i <= _totalPages; i++) {
   var canvas = this._printpages(i);
  _printWindow.document.write('<img src="' + canvas.toDataURL() + '"style="border:1px solid;height:"' + _pageHeight + '"px;margin:0px"><br />');
}
_printWindow.document.write('</center></body></html>');
_printWindow.document.close();
_printWindow.print();
var\u printWindow=window.open(“”);
_printWindow.document.write(“”);
_printWindow.document.write(“”);

对于(var i=1;i您在完成
的编写后直接调用
print()
,请尝试将样式
宽度:100%;
添加到
标记,我会认为您在写入所有内容之前就已经命中了print语句。这就是为什么它是随机的。您是否检查了canvas变量的打印结果而没有循环?
var nImages = _totalPages;
function imageLoaded() {
    if (--nImages === 0) {
        _printWindow.print();
    }
}

// ...snip...

// replace your `for` loop with the following:
for (var i = 1; i <= _totalPages; i++) {
    var img = new Image;
    img.addEventListener('load', imageLoaded);
    img.src = /* get the data URL from the canvas */;

    // here, add in your style properties

    _printWindow.document.body.appendChild(img);
}