JS實現Chrome瀏覽器打印

利用HTML的iframe標籤實現頁面打印效果

var iframe = document.createElement('IFRAME');
var doc = null;
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
doc.write('');//放入需要打印的內容,最好拼接爲一個完整的html
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();

屏蔽打印預覽效果

找到Chrome瀏覽器快捷方式,右鍵選擇‘屬性’,在目標欄添加  --kiosk-printing

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章