html2canvas 页面截屏
$(document).ready(function () { $(".example1").on("click", function (event) { var width = $(".swiper-slide").width(); var height = $(".swiper-slide").height(); event.preventDefault(); html2canvas($(".swiper-slide"), { allowTaint: true, taintTest: false, onrendered: function (canvas) { canvas.id = "mycanvas"; //document.body.appendChild(canvas); //生成base64图片数据 var dataUrl = canvas.toDataURL(); var newImg = document.createElement("img"); newImg.src = dataUrl; document.body.appendChild(newImg); // var image = canvas.toDataURL("image/png"); // var w = window.open('about:blank', 'image from canvas'); // w.document.write("<img src='" + image + "' alt='from canvas'/>"); // var image = myCanvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // window.location.href = image; }, width: width * 2, height: height * 2 }); });