print() 方法用于打印當前窗口的內容,支持部分或者整個網頁打印。
調用 print() 方法所引發的行為就像用戶單擊瀏覽器的打印按鈕。通常,這會產生一個對話框,讓用戶可以取消或定制打印請求。
win10下測試ie11、chrome、firefox、360、edge 都可以成功去掉頁眉頁腳;
<!DOCTYPE html><html><head> <title>打印</title> <meta charset="utf-8"> <style> .printBox { width: 300px; height: 300px; border: 1px solid blue; } </style> <!-- 打印的樣式--> <style media="print"> @page { size: auto; margin: 0mm; } </style></head><body><div class="printBox"> this is content!!!<br> 點擊按鈕打印</div><button onclick='print_page()'>打印</button></body><script type="text/javascript"> function print_page() { if (!!window.ActiveXObject || "ActiveXObject" in window) { //是否ie remove_ie_header_and_footer(); } window.print(); } function remove_ie_header_and_footer() { var hkey_path; hkey_path = "HKEY_CURRENT_USER//Software//Microsoft//Internet Explorer//PageSetup//"; try { var RegWsh = new ActiveXObject("WScript.Shell"); RegWsh.RegWrite(hkey_path + "header", ""); RegWsh.RegWrite(hkey_path + "footer", ""); } catch (e) { } }</script></html>以上這篇js 客戶端打印html 并且去掉頁眉、頁腳的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答