本文介绍了html2canvas基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <html>

    <head>
    <title>test</title>
    <script src="external/jquery-1.6.2.js"></script>
    <script type="text/javascript" src="js/html2canvas.js"></script>

    <script type="text/javascript">
     $(document).ready(function() {
     $('body').html2canvas();
     var queue = html2canvas.Parse();
     var canvas = html2canvas.Renderer(queue,{elements:{length:1}});
     var img = canvas.toDataURL()
     window.open(img);
 });
    </script>
    </head>

    <body>
    <h1>Testing</h1>
    <img src='http://localhost:8080/test/images/1.jpg'>
    </body>
    </html>

我应该不会看到一个以该网页为图像打开的新窗口?我想念什么?

Shouldn't I be seeing a new window open up with this webpage as an image? What am I missing?

推荐答案

如果您是html2canvas的新手,以下是一些入门指南.希望对别人有帮助.

If you're new to html2canvas as I am- below is some boilerplate code to get you started. Hope it helps someone else.

<html>
<head>
<meta charset="utf-8"/>
<title>test2</title>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>


<script type="text/javascript">
$(document).ready(function() {
var target = $('body');
html2canvas(target, {
    onrendered: function(canvas) {
    var data = canvas.toDataURL();
    alert(data);
    // data is the Base64-encoded image
    }
});
});
</script>

</head>
<body>
<h1>Testing</h1>
<h4>One column:</h4>
<table border="1">
<tr>
  <td>100</td>
</tr>
</table>

</body>
</html>

注意-我正在使用v0.34.

Note- I am using v0.34.

然后,您可以将 toDataUrl()用作另一个html页面中的src标记(或您想从此处执行的任何操作):

You can then use the toDataUrl() as a src tag in another html page (or whatever you want to do from here):

<html>
<head>
<meta charset="utf-8"/>
<title>TEST toDataUrl() DATA FROM PREVIOUS CODE PAGE</title>
</head>
<body>
<h1>Testing html2canvas</h1>
<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAKWCAYAAACidsIoAAAVNUlEQVR4nO3dP4gc1x0H8G+xhRoJIWRQCoPtAxsSsBE4ITYk9haBNAIbDDF2Zbgi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