1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > js浏览器的打印和去除页眉和页脚

js浏览器的打印和去除页眉和页脚

时间:2021-11-20 05:48:29

相关推荐

js浏览器的打印和去除页眉和页脚

<div id="print-conent"><div id="title" style="text-align:center;font-weight:bolder;font-size:16px;"><h4><span>患者姓名【{{vm.patientName}}】</span><span>性别【{{vm.sex}}】</span><span>透析病案号【{{vm.patientNo}}】</span></h4></div><div id="printDialysisDetectionPage"><table ng-table="vm.tableTxjl" class="table"><colgroup><col width="8%"><col width="10%"><col width="8%"><col width="10%"><col width="12%"><col width="16%"><col width="8%"><col width="10%"><col width="8%"><col width="10%"></colgroup><tr ng-repeat="item in vm.printList"><td><div class="conent1"><div class="row date"><div class="col-md-12">日期:{{item.date|date:yyyy-MM-dd}}</div></div>@*<div>{{item.content1}}</div>*@<div ng-bind-html="item.content" style="font-size:13px;"></div><div class="creatorUserName" style="text-align:right"><span>医生:{{item.creatorUserName}}</span></div></div></td></tr></table></div></div>

js

//去除页眉和页脚window.οnbefοreprint = beforePrint;window.οnafterprint = afterPrint; function beforePrint() {$('.navbar').hide(); //隐藏头部$('#page-header').hide(); //隐藏面包屑$('#block-region-side-pre').hide(); //隐藏左侧导航栏}//打印之后将隐藏掉的信息再显示出来 function afterPrint() {$('.navbar').show(); //显示头部$('#page-header').show(); //显示面包屑$('#block-region-side-pre').show(); //显示左侧导航栏}vm.myPreview = function () {var printConent = document.getElementById('print-conent').innerHTML;var page = window.open('', '_blank');// 打开一个新窗口,用于打印console.log(page,"page");page.document.write(printConent);// 写入打印页面的内容page.print();// 打印var userAgent = navigator.userAgent;if ((userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1) || (userAgent.indexOf("Edge") > -1) || (userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1)) {// IE浏览器page.document.execCommand('print');} else {console.log('not IE');}page.close();// 关闭打印窗口}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。