欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js 客戶端打印html 并且去掉頁眉、頁腳的實例

 更新時間:2017年11月03日 08:22:27   作者:風(fēng)吹De麥浪  
下面小編就為大家?guī)硪黄猨s 客戶端打印html 并且去掉頁眉、頁腳的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

print() 方法用于打印當(dāng)前窗口的內(nèi)容,支持部分或者整個網(wǎng)頁打印。

調(diào)用 print() 方法所引發(fā)的行為就像用戶單擊瀏覽器的打印按鈕。通常,這會產(chǎn)生一個對話框,讓用戶可以取消或定制打印請求。

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 并且去掉頁眉、頁腳的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論