Javascript Html2canvas打印屏幕截图

Javascript Html2canvas打印屏幕截图,javascript,html,css,asp.net,html2canvas,Javascript,Html,Css,Asp.net,Html2canvas,我在.aspx中有这段代码,它应该打印我的web函数的选定部分 <div id="test" class="body-content animated fadeIn"> <a href="javascript:getScreenshot()"> Get Sreenshot </a> <script> function get

我在.aspx中有这段代码,它应该打印我的web函数的选定部分

           <div id="test" class="body-content animated fadeIn">
                <a href="javascript:getScreenshot()"> Get Sreenshot </a>
                <script>
                    function getScreenshot() {
                        html2canvas(divprint, {
                            onrendered: function(canvas) {
                                var canvasImg = canvas.toDataURL("image/jpg");
                                $('#test').html('<img src="'+canvasImg+'" alt="">');
                            }
                        });
                        var printContent = document.getElementById("test");
                        var printWindow = window.open("", "","left=50,top=50");
                        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();
                    }
                </script>
                ...

函数getScreenshot(){
html2canvas(divprint{
onrendered:函数(画布){
var canvasImg=canvas.toDataURL(“image/jpg”);
$('#test').html('');
}
});
var printContent=document.getElementById(“测试”);
var printWindow=window.open(“,”,“left=50,top=50”);
printWindow.document.write(printContent.innerHTML);
printWindow.document.write(“”);
printWindow.document.write($(window.load)(function(){print();close();}););
printWindow.document.close();
}
...
但是点击文本“Get Sreenshot”什么也没发生。你明白为什么吗? 当我移除

                       html2canvas(divprint, {
                            onrendered: function(canvas) {
                                var canvasImg = canvas.toDataURL("image/jpg");
                                $('#test').html('<img src="'+canvasImg+'" alt="">');
                            }
                        });
html2canvas(divprint{
onrendered:函数(画布){
var canvasImg=canvas.toDataURL(“image/jpg”);
$('#test').html('');
}
});

它或多或少运行良好

最新版本的html2canvas使用承诺而不是“onrendered”回调。
例如


你加载了所有的库吗?你的控制台有什么错误?我已经在命令“npm安装html2canvas”中添加了这个选项,除此之外,没有其他东西可以正常工作,谢谢!你知道如何解决变色和变焦的问题吗?变色和变焦有什么问题?我在你的问题中看不到这一点。请看这里的新问题:
html2canvas(document.querySelector('#my-thing')).then(function(canvas) {
  // do something with canvas here.
  console.log(canvas);
});