javascript - html2canvas打印截图

标签 javascript html css asp.net html2canvas

我在 .aspx 中有这段代码,它应该打印我的网络功能的选定部分。

           <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>
                ...

但是点击文本“Get Sreenshot”没有任何反应。你明白为什么吗? 当我删除

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

它或多或少地工作

最佳答案

最新版本的 html2canvas 使用 promises 而不是 'onrendered` 回调。
例如。

html2canvas(document.querySelector('#my-thing')).then(function(canvas) {
  // do something with canvas here.
  console.log(canvas);
});

关于javascript - html2canvas打印截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51823015/

相关文章:

javascript - 如何从 Knockout.js 的复选框列表中只选择一个复选框

php - IE 浏览器中 Joomla 网站的下拉菜单问题

jquery - bootstrap formValidation 复选框组未添加 has-success

javascript - CodeMirror - 从编辑器外部获取 linting 结果

javascript - 如何从 HTML 标签中移除 CSS 属性

javascript - AngularJS 设计模式 : Should I use factories to create constructor functions?

Jquery,点击,隐藏div并替换为隐藏的div

javascript - 将 JavaScript 数组转换为 JSON 格式 :JavaScript

html - 简单的 HTML + CSS 页面中出现奇怪的差距

html - html 表格中不需要的垂直填充