var printPage = window.open("", "Printing...", "");
var value = document.getElementById('PrintArea').innerHTML;
printPage.document.open();
printPage.document.write("<HTML><head></head><BODY onload='window.print();window.close()'>");
printPage.document.write("<PRE>");
printPage.document.write(value);
printPage.document.write("</PRE>");
printPage.document.write("</BODY></HTML>");
printPage.document.close();
方法二:(存成圖片,但是不支援IE,且open要注意彈跳視窗問題)
var printPage = window.open("", "Printing...", "");
html2canvas(document.getElementById('PrintArea')).then(function (canvas) {
printPage.document.open();
printPage.document.write("<HTML><head><title>友善列印</title>");
printPage.document.write("</head>");
printPage.document.write("<body style='zoom:80%' onload='window.print();window.close()'>");
printPage.document.write("<pre style='overflow-x: hidden'>"); //寫死沒有X軸Scroll功能
printPage.document.write("<div'>");
printPage.document.write("<img src='" + canvas.toDataURL() + "'/>");
printPage.document.write("</div'>");
printPage.document.write("</pre>");
printPage.document.write("</body></HTML>");
printPage.document.close();
});