亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js 客戶(hù)端打印html 并且去掉頁(yè)眉、頁(yè)腳的實(shí)例

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

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

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

win10下測(cè)試ie11、chrome、firefox、360、edge 都可以成功去掉頁(yè)眉頁(yè)腳;

<!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>
 點(diǎn)擊按鈕打印
</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 客戶(hù)端打印html 并且去掉頁(yè)眉、頁(yè)腳的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論