Home > Web Front-end > JS Tutorial > Example of js client printing html and removing header and footer

Example of js client printing html and removing header and footer

韦小宝
Release: 2018-01-17 10:40:35
Original
1674 people have browsed it

下面小编就为大家带来一篇js 客户端打印html 并且去掉页眉、页脚的实例。小编觉得挺不错的,现在就分享js源码给大家,也给大家做个参考。对js感兴趣的一起跟随小编过来看看吧

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>
<p class="printBox">
 this is content!!!<br>
 点击按钮打印
</p>
<button onclick=&#39;print_page()&#39;>打印</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>
Copy after login

以上这篇js 客户端打印html 并且去掉页眉、页脚的实例就是小编分享给大家的全部内容了,希望能给大家一个参考!!

相关推荐:

原生JavaScript实现Ajax异步请求

基于JavaScript实现五子棋游戏

选择最适合你的JavaScript框架解析

The above is the detailed content of Example of js client printing html and removing header and footer. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template