js控制打印 去掉页眉页尾

<html>
<head>
<script language="javascript">
 var HKEY_Root,HKEY_Path,HKEY_Key;
  HKEY_Root="HKEY_CURRENT_USER";
  HKEY_Path="//Software//Microsoft//Internet Explorer//PageSetup//";
  //设置网页打印的页眉页脚为空
  function PageSetup_Null()
  {
  try
  {
      var Wsh=new ActiveXObject("WScript.Shell");
   HKEY_Key="header";
      Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
      HKEY_Key="footer";
      Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
  }
  catch(e){}
  }

  function preview()
 {
  document.getElementById('print').style.display='';
  document.getElementById("body").style.background="white";
  bdhtml=window.document.body.innerHTML;
  sprnstr="<!--startprint-->";
  eprnstr="<!--endprint-->";
  prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
  prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
  window.document.body.innerHTML=prnhtml;
  PageSetup_Null();
  window.print();
 }

</script>
</head>
<body id=“body”>

<input type="button" name="print" value="预览并打印" οnclick="preview()">


<!--startprint-->

<table id="print">
...........要打印的部分

</table>

 <!--endprint--> 
 
</body> 
</html>

要在 vue-print-nb 中自定义头和页脚并进行局部打印,可以按照以下步骤进行: 1. 在你的组件中引入 vue-print-nb: ```javascript import vuePrint from 'vue-print-nb'; ``` 2. 创建一个打印模板并将其传递给 vue-print-nb 组件: ```html <vue-print :printContent="printTemplate" :showPrint="showPrint"></vue-print> ``` 其中 `printTemplate` 是要打印的内容,`showPrint` 控制是否显示打印弹窗。 3. 在 `printTemplate` 中添加自定义的头和页脚,例如: ```html <div class="page-header">我的自定义头</div> <div class="page-footer">我的自定义页脚</div> <div class="page-body"> <!-- 打印内容 --> </div> ``` 这里我们使用了三个 `<div>` 标签来分别代表头、页脚打印内容。 4. 在样式表中为头和页脚添加样式: ```css .page-header { position: absolute; top: 0; left: 0; width: 100%; height: 50px; background-color: #f5f5f5; text-align: center; font-size: 24px; line-height: 50px; } .page-footer { position: absolute; bottom: 0; left: 0; width: 100%; height: 50px; background-color: #f5f5f5; text-align: center; font-size: 16px; line-height: 50px; } ``` 5. 在打印按钮的点击事件中设置要打印的内容为当前组件中的某个元素,例如: ```javascript print() { this.printTemplate = this.$refs.printContent.innerHTML; this.showPrint = true; } ``` 这里我们使用了 `$refs` 来获取组件中名为 `printContent` 的元素,将其转成 HTML 字符串并赋值给 `printTemplate`,然后显示打印弹窗。 6. 最后,在打印弹窗中选择“局部打印”选项,就可以只打印指定的内容了。 希望这些步骤可以帮助你实现自定义页脚并进行局部打印
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值