分享web开发知识

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

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

js打印小结

发布时间:2023-09-06 01:50责任编辑:赖小花关键词:js
<script type="text/javascript"> 
//打印必备参数var hkey_root,hkey_path,hkey_key;hkey_root="HKEY_CURRENT_USER";hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";//打印机设置function toPageSetup(){document.all.WebBrowser.ExecWB(8,1);//打印机设置}//打印预览function toPreview(){document.all.WebBrowser.ExecWB(7,1);}/** 功能:打印* 参数:isShowSetup 是否显示打印设置*/function printPage(isShowSetup){pagesetup_null();window.print(); ???}//配置网页打印的页眉页脚为空function pagesetup_null(){ try{ var RegWsh = new ActiveXObject("WScript.Shell"); hkey_key="header"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");hkey_key="footer";RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");//&b 第&p页/共&P页 &b}catch(e){}}</script>

 jsp中引入:

<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>

jsp中引入样式:

<style media="print">.Noprint {display: none ?//不打印的内容的class}.PageNext {page-break-after: always; ??//在元素后面插入分页}</style>

 法二:直接全部引进去,做相关内容的替换(有提示!)调用方法即可


function isIE(){ ???if (!!window.ActiveXObject || "ActiveXObject" in window) ?????return true; ?????else ?????return false; }/** * 打印指定页面 * @return */function printPage() { ???window.focus(); ?????????????????if(isIE()){ ???????//$(".td03").css("border","0px"); ???????var printPage=document.getElementById("divPage");//要打印div的Id ???????var oldStr=document.body.innerHTML; ???????var newStr=printPage.innerHTML; ???????document.body.innerHTML=newStr; ???????????????pagesetup_null(); ???????????????document.body.className += ‘ ext-ie‘; ???????document.execCommand(‘print‘, false, null); ???????????????????????????document.body.innerHTML=oldStr; ???????????????return false; ???}else{ ???????//$(".td03").css("border","0px");//去样式 ???????var printPage=document.getElementById("divPage");//要打印div的Id ???????var oldStr=document.body.innerHTML; ???????var newStr=printPage.innerHTML; ???????document.body.innerHTML=newStr; ???????????????pagesetup_null();//去页眉页脚 ???????window.print(); ???????????????document.body.innerHTML=oldStr; ???????????????return false; ???} ???????//打印相关参数 ???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 = new ActiveXObject("WScript.Shell"); ??????????????????????hkey_key="header"; ????????????RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); ???????????hkey_key="footer"; ???????????RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); ???????????//&b 第&p页/共&P页 &b ???????}catch(e){} ???}

js打印小结

原文地址:https://www.cnblogs.com/dapeng001/p/8921734.html

知识推荐

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