使用print()函數帶入document可將本頁面文本資料,直接由瀏覽器內建列印的對話視窗開啟列印。
HTML
<input name="print" onclick="varitext()" type="button" value="列印此頁"></input>
Javascript
function varitext(){
var text = document
print(text)
}
Demo
See the Pen JavaScript print() document by Leon Cheng (@jq153387) on CodePen.