js 将网页内容生成图片
$(function () {
$("#saveimg_btn").on("click",function (event) {
event.preventDefault();
html2canvas($("#printtable"), {
allowTaint: true,
taintTest: false,
onrendered: function (canvas) {
canvas.id = "mycanvas";
//document.body.appendChild(canvas);
//生成base64图片数据
var dataUrl = canvas.toDataURL("image/png");
var newImg = document.createElement("img");
newImg.src = dataUrl;
document.body.appendChild(newImg);
$(".no_print").hide();
$("#printtable").hide();
}
});
});
});
<button id="saveimg_btn">生成图片</button>
<table id="printtable" class="ticket">
<tr>
<td>test</td>
</tr>
</table>