<style media="print">
.Noprint { display: none; } /* 打印時隱藏按鈕、導航等 */
.PageNext { page-break-after: always; } /* 強制分頁 */
</style>
<body>
<div class="Noprint" align="center">
<button onclick="window.print()">打印</button>
<button onclick="printSetup()">頁面設置</button>
<button onclick="printPreview()">打印預覽</button>
</div>
<!-- 第 1 頁內容 -->
111<br/>111<br/>111<br/>
<div class="PageNext"></div>
<!-- 第 2 頁內容 -->
222<br/>222<br/>222<br/>
<div class="PageNext"></div>
<!-- 第 3 頁內容 -->
333<br/>333<br/>333<br/>
<div class="PageNext"></div>
...
</body>
function printIt() {
if (confirm('確定打印嗎?')) window.print();
}
function printSetup() { /* 瀏覽器不提供 JS 調用頁面設置對話框,通常由用戶手動操作 */ }
function printPreview() { /* 現代瀏覽器 print() 會自動彈出預覽對話框 */ }
僅限 IE / IE 模式 / 基於 IE 内核的瀏覽器(如舊版 360、QQ 瀏覽器兼容模式)。
<OBJECT id="wb" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" width="0" height="0"></OBJECT>
function printWithDialog() { wb.execWB(6, 1); } // 6=PRINT, 1=提示對話框
function printDirect() { wb.execWB(6, 6); } // 6=PRINT, 6=直接打印無對話框
function printSetup() { wb.execWB(8, 1); } // 8=PAGE_SETUP
function printPreview() { wb.execWB(7, 1); } // 7=PRINT_PREVIEW
<html>
<head>
<title>JS 分頁批量打印 (僅 IE)</title>
<style media="print">
.Noprint { display: none; }
.PageNext { page-break-after: always; }
</style>
<script>
function printWithAlert() { document.all.WebBrowser.ExecWB(6,1); }
function printWithoutAlert() { document.all.WebBrowser.ExecWB(6,6); }
function printSetup() { document.all.WebBrowser.ExecWB(8,1); }
function printPreview() { document.all.WebBrowser.ExecWB(7,1); }
</script>
</head>
<body>
<OBJECT id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" style="display:none"></OBJECT>
<table align="center" class="NOPRINT">
<tr><td>
<button onclick="printWithAlert()">打印(帶對話框)</button>
<button onclick="printWithoutAlert()">直接打印</button>
<button onclick="printSetup()">打印設置</button>
<button onclick="printPreview()">打印預覽</button>
</td></tr>
</table>
<div class="NOPRINT">以下為打印區:<br></div>
<hr class="NOPRINT">
<table class="PageNext"><tr><td colspan="2">第一頁內容...</td></tr></table>
<hr class="NOPRINT">
<div class="PageNext">第二頁內容...</div>
<hr class="NOPRINT">
第三頁內容...
</body>
</html>