SoFunction
Updated on 2025-04-11

js client prints html and removes the header and footer instances

The print() method is used to print the content of the current window and supports printing of part or entire web pages.

Calling the print() method causes behavior like a user clicking the browser's print button. Typically, this creates a dialog box that allows the user to cancel or customize the print request.

Testing ie11, chrome, firefox, 360, and edge under win10 can successfully remove the header and footer;

<!DOCTYPE html>
<html>
<head>
 <title>Print</title>
 <meta charset="utf-8">
 <style>
  .printBox {
   width: 300px;
   height: 300px;
   border: 1px solid blue;
  }
 </style>
 <!-- Print的样式-->
 <style media="print">
  @page {
   size: auto;
   margin: 0mm;
  }
 </style>
</head>

<body>
<div class="printBox">
 this is content!!!<br>
 点击按钮Print
</div>
<button onclick='print_page()'>Print</button>
</body>

<script type="text/javascript">
 function print_page() {
  if (!! || "ActiveXObject" in window) { //Is it ie   remove_ie_header_and_footer();
  }
  ();
 }

 function remove_ie_header_and_footer() {
  var hkey_path;
  hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
  try {
   var RegWsh = new ActiveXObject("");
   (hkey_path + "header", "");
   (hkey_path + "footer", "");
  } catch (e) {
  }
 }
</script>
</html>

The above example of printing html on the js client and removing the header and footer is all the content I share with you. I hope you can give you a reference and I hope you support me more.