生活随笔
收集整理的這篇文章主要介紹了
打印功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在web中開發(fā)打印功能
截圖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保存打印區(qū)域,避免影響原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);}} }); }
總結
以上是生活随笔為你收集整理的打印功能的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。