生活随笔
收集整理的这篇文章主要介绍了
打印功能
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
在web中开发打印功能
截图1
截图2
代码
/*截图打印统计饼状图*/document.querySelector(".countImagePrint").onclick = function(){html2canvas(document.getElementById("alarmCountContent"), {//截图 allowTaint : true, taintTest : false, onrendered : function(canvas) { //生成base64图片数据 var dataUrl = canvas.toDataURL(); var newImg = document.createElement("img"); newImg.src = dataUrl; //利用iframe保存打印区域,避免影响原document的bodyvar iframe = document.createElement('iframe');var doc = null;iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');document.body.appendChild(iframe);doc = iframe.contentWindow.document;//写入需打印的内容doc.write('<img src="'+newImg.src+'" />');doc.close();iframe.contentWindow.focus();iframe.contentWindow.print();if (navigator.userAgent.indexOf("MSIE") > 0){document.body.removeChild(iframe);}} }); }
总结
以上是生活随笔为你收集整理的打印功能的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。