ydo*_*oow 2 html javascript html2canvas
我正在使用构建网页打印功能html2canvas。
function printthispage() {
html2canvas($("#mydiv"), {
onrendered: function (canvas) {
var myImage = canvas.toDataURL("image/png");
var printWindow = window.open(myImage);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
});
}
Run Code Online (Sandbox Code Playgroud)
但是,窗户立即打开和关闭。我试过删除close(),图像显示在新窗口上,但未触发打印功能。有什么不对?
小智 6
试试这个,它将起作用:
html2canvas($("#mydiv"), {
onrendered: function(canvas) {
var myImage = canvas.toDataURL("image/png");
var tWindow = window.open("");
$(tWindow.document.body)
.html("<img id='Image' src=" + myImage + " style='width:100%;'></img>")
.ready(function() {
tWindow.focus();
tWindow.print();
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12712 次 |
| 最近记录: |