1.引入jscss
<script src="https://cdn.bootcss.com/html2canvas/0.4.1/html2canvas.js"></script>html
2.使用canvas
function DownLoadDomImg(el) { html2canvas(el, { // 页面高度 height: el.height, // 页面宽度 width: el.width, onrendered: function(canvas) { var mA = document.createElement("a"); mA.href = canvas.toDataURL() mA.setAttribute('download', 'download.png'); mA.click(); console.log(mA);
// 若是是ie浏览器 则须要 使用ie浏览器的下载方法 进行下载 一会补充 } }); } // 使用 DownLoadDomImg(document.getElementById("box"))
这个时候 传入想要下载的 元素id 调用此方法的时候就能够实现下载浏览器