js 客户端打印html 并且去掉页眉、页脚

print() 方法用于打印当前窗口的内容,支持部分或者整个网页打印。

调用 print() 方法所引发的行为就像用户单击浏览器的打印按钮。通常,这会产生一个对话框,让用户可以取消或定制打印请求。

win10下测试ie11、chrome、firefox、360、edge 都可以成功去掉页眉页脚;

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title>打印</title>
 5     <meta charset="utf-8">
 6     <style>
 7         .printBox {
 8             width: 300px;
 9             height: 300px;
10             border: 1px solid blue;
11         }
12     </style>
13     <!-- 打印的样式-->
14     <style media="print">
15         @page {
16             size: auto;
17             margin: 0mm;
18         }
19     </style>
20 </head>
21
22 <body>
23 <div class="printBox">
24   this is content!!!<br>
25     点击按钮打印
26 </div>
27 <button onclick=‘print_page()‘>打印</button>
28 </body>
29
30 <script type="text/javascript">
31     function print_page() {
32         if (!!window.ActiveXObject || "ActiveXObject" in window) { //是否ie
33             remove_ie_header_and_footer();
34         }
35         window.print();
36     }
37
38     function remove_ie_header_and_footer() {
39         var hkey_path;
40         hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
41         try {
42             var RegWsh = new ActiveXObject("WScript.Shell");
43             RegWsh.RegWrite(hkey_path + "header", "");
44             RegWsh.RegWrite(hkey_path + "footer", "");
45         } catch (e) {
46         }
47     }
48 </script>
49 </html>
时间: 2024-08-29 18:16:02

js 客户端打印html 并且去掉页眉、页脚的相关文章

jquery.jqprint-0.3.js打印功能 以及页眉页脚设置显示与否

项目中需要打印 搜索使用了jquery.jqprint-0.3.js 遇到一些样式问题,现在已经解决 ,记录下来供大家参考. 下面图显示为我页面中的样式 打印需要一列显示,解决办法就是写到行内元素上,页面显示写到页面style样式中 下面为谷歌显示的打印效果,可以勾除页眉页脚设置 火狐浏览器需要这样设置页眉页脚 打印-->页面设置  设置完以后打印效果一样 原文地址:https://www.cnblogs.com/wdd-cindy/p/9151089.html

js:打印页面且自定义页眉页脚

1,下载jqprint.js,如果报错,可能是jquery的版本太低了. 解决:1,更换jquery 2,或者引入 jquery-migrate.min.js <input type="button" id="printtest" value="打印" onclick="printtest()"> <div id="printcontent"> <div>test<

关于JavaScript打印去掉页眉页脚

因为这个问题,Google和百度都查了个遍,网上主要解决方案都是这一个代码: <script language="JavaScript"> var hkey_root,hkey_path,hkey_key; hkey_root="HKEY_CURRENT_USER"; hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; // 设置网页打印的页眉页脚为空

js中window.print()去除页眉页脚

//jsp打印时去除页眉页页脚 打印前加入下面代码即可 var HKEY_Root,HKEY_Path,HKEY_Key; HKEY_Root="HKEY_CURRENT_USER"; HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; var head,foot,top,bottom,left,right; var Wsh=new ActiveXObject("WScrip

js 调用打印机(可清除页眉页脚)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title&

javascript打印设置页眉页脚

<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 RegWsh

IE浏览器打印的页眉页脚设置解决方法

首先说明问题:默认情况下,通过IE的打印对话框,打印出来的内容都有页眉和页脚的. 查看ie的页面设置发现如右图中,页眉页脚. 下面先说明&w&bPage&p of &P , &u&b&d的含义 &w - 窗口标题 &u - 页面地址 &d - 短日期格式,如10/12/2006 &D - 长日期格式,如Tursday, October 12, 2006 &t - 12小时制时间 &T - 24小时制时间

c# iText 生成PDF 有文字,图片,表格,文字样式,对齐方式,页眉页脚,等等等,

#region 下载说明书PDF protected void lbtnDownPDF_Click(object sender, EventArgs e) { int pid = ConvertHelper.GetInteger(Request["PID"]); pds = p.GetModel(pid); #region 第一种方法 DataTable datatable = new DataTable(dt.ToString()); try { string Url1 = &quo

【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页

itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类,实现第几页/共几页,方便各位刚进入itext的童鞋调用.2013年9月16日 14:51:01 背景:网上流传的都是一些简单的demo,直接扔个A4文档就说实现了,其实很坑的,换个A4横版打印,那些代码就不行了,所以自己搞了这个出来. 如果页面看着排版不好,请移步我的百度空间 :http://hi