【发布时间】:2018-08-14 06:23:02
【问题描述】:
我正在创建一个网页,我需要制作一个打印选定区域的按钮。经过几次搜索,一切都让我实现了html2canvas。 我安装了它 npm install html2canvas 在命令提示符下。在他们提到的官方 html2canvas 网站中 import html2canvas from 'html2canvas'; 我想我需要在我的 aspx 文件顶部添加(?) 到目前为止,我已经编写了这个代码部分:
function getScreenshot() {
alert("bob");
html2canvas(document.body, {
onrendered: function(canvas) {
var canvasImg = canvas.toDataURL("image/jpg");
$('#test').html('<img src="' + canvasImg + '" alt="">');
}
});
var printContent = document.getElementById("row");
var printWindow = window.open("", "");
printWindow.document.write(printContent.innerHTML);
printWindow.document.write("<script src=\'http://code.jquery.com/jquery-1.10.1.min.js\'><\/script>");
printWindow.document.write("<script>$(window).load(function(){ print(); close(); });<\/script>");
printWindow.document.close();
};
<div id="test" class="body-content animated fadeIn">
<a href="javascript:getScreenshot()">
<img src="Images/printer.png" width="40" height="40" align="right">
</a>
</div>
问题是当我单击按钮时,没有打开打印窗口。该按钮肯定有效,因为我得到了警报窗口。 我缺少什么让这个工作?可以出一个安装程序吗?可以是坏属性实现吗?
【问题讨论】:
-
我想问题只是没有加载 html2canvas 库。 npm install 会将其安装在 node_modules 中,并且在大多数情况下位于您的文档根目录 (wwwroot) 之外。您应该检查您的浏览器调试控制台是否有错误。
标签: javascript jquery html2canvas