分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

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

发布时间:2023-09-06 01:22责任编辑:彭小芳关键词:js

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) { //是否ie33 ????????????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>

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

原文地址:http://www.cnblogs.com/CandyManPing/p/7775083.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved