JS中FireFox新开窗口预览打印处理的方式
仅提供思路,勿喷如下↓
/**
* 打印方法
* @param dom 要被打印的dom元素
* @param parentClassName 该组件的页面根组件class名
* @param pageMargin @page中的maring值
*/
static print = (dom, parentClassName = '', pageMargin = '20px') => {
if (navigator.userAgent.indexOf("Firefox") > ) { let previewDom = document.getElementById('previewDom_serviceCharges');
if (previewDom && previewDom.offsetHeight) {
const imgNumber = parseInt(String(previewDom.offsetHeight / )) + ; let webConfig = (<any>window).config;
let hostAddress = webConfig.isDebug ? `http://${window.location.host}` : `http://${window.location.host}/erpfront/dist`;
let backimg = document.createElement('div'), htmlStr = '';
for (let i = ; i < imgNumber; i++) {
htmlStr += `
<img src='${hostAddress}/assets/images/contract-background.jpg'>
` ;
}
backimg.innerHTML = htmlStr;
backimg.setAttribute('style', `
position: absolute;
bottom: 0px;
padding: 0px;
margin: 0px;
top: ;
z-index: -;
width: %;
`);
//backimg.className = 'backimg';
previewDom.appendChild(backimg);
} const domPrint = document.createElement('div');
domPrint.className = parentClassName;
domPrint.id = 'dom-content-for-print-printutils';
domPrint.innerHTML = dom.outerHTML; let page = window.open('', '_blank');// 打开一个新窗口,用于打印
page.document.body.innerHTML = domPrint.outerHTML;// 写入打印页面的内容 const domPrintStyle = document.createElement('style');
domPrintStyle.id = 'dom-style-for-print-printutils';
domPrintStyle.innerHTML = PrintUtils.getFirefoxStyle(pageMargin); page.document.head.appendChild(domPrintStyle); page.print();// 打印
page.close();// 关闭打印窗口 }
}
static getFirefoxStyle(pageMargin: any) {
PrintUtils.firefoxStyleString = `
@media print {
body {
float: none !important;
position: static !important;
display: inline;
page-break-after: always;
}
body > * {
display: none;
}
body * {
color: # !important;
border-color: # !important;
}
@page {
margin: ${pageMargin}
}
#dom-content-for-print-printutils{
display: block
}
}
.icon {
margin-left: 11px;
font-size: 18px;
color: #32c5d2;
font-weight: ;
cursor: pointer;
}
.hr {
width: %;
color: #f5f5f5;
}
.inputCenter {
position: relative;
top: 20px;
}
.contractPreview {
margin: 0px auto;
width: %;
border: none;
position: relative;
z-index: ;
overflow: hidden;
}
return PrintUtils.firefoxStyleString;
}
JS中FireFox新开窗口预览打印处理的方式的更多相关文章
- Vue.js 3.0 新特性预览
总结起来,Vue 3 以下方面值得我们期待 : 更快 更小 更易于维护 更多的原生支持 更易于开发使用 完整的PPT:docs.google.com/presentatio… Evan 和 Vue 团 ...
- 基于Three.js的360X180度全景图预览插件
基于Three.js的360X180度全景图预览插件 时间 2015-08-12 10:01:10 HTML5中国 原文 http://www.html5cn.org/article-8621-1 ...
- js实现图片上传预览及进度条
原文js实现图片上传预览及进度条 最近在做图片上传的时候,由于产品设计的比较fashion,上网找了比较久还没有现成的,因此自己做了一个,实现的功能如下: 1:去除浏览器<input type= ...
- js实现移动端图片预览:手势缩放, 手势拖动,双击放大...
.katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...
- C# 9.0 新特性预览 - 类型推导的 new
C# 9.0 新特性预览 - 类型推导的 new 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大 ...
- C# 9.0 新特性预览 - 空参数校验
C# 9.0 新特性预览 - 空参数校验 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它 ...
- C# 9.0 新特性预览 - 顶级语句
C# 9.0 新特性预览 - 顶级语句 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它们 ...
- C# 9.0 新特性预览 - init-only 属性
C# 9.0 新特性预览 - init-only 属性 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章 ...
- 20天等待,申请终于通过,安装和体验IntelliJ IDEA新UI预览版
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于IDEA的预览版 IDEA会启用新的UI,这事情之 ...
随机推荐
- SpringBoot常见报错及解决方法
问题一 Field redisUtil in com.sui.demo.controller.redisController required a bean of type 'com.sui.demo ...
- PHP回顾(2)
print_r()打印输出原格式,就加上标签<pre>.例子:echo '<pre>'; print_r($arr); echo '<pre>'; 添加数组的时候, ...
- jquery button选择器 语法
jquery button选择器 语法 作用::button 选择器选取类型为 button 的 <button> 元素和 <input> 元素.大理石平台价格表 语法:$(& ...
- HFUUOJ1023 闷声发大财 概率dp
题意 xyq有\(n\)个骰子,第\(i\)个骰子有\(a_i\)面,每次xyq都会把\(n\)个骰子搞一遍,其中的最小值作为结果,问最终结果的期望\(\mod (10^9+7 )\). 分析 lfx ...
- 用python进行服务器的监控
用python进行服务器的监控 在linux服务器中,一切皆为文件,就是说,服务器运行的个中信息,其实是可以从某些文件中查询得到的:百度后,你会知道,在Linux系统中,有一个/proc的虚拟文件系统 ...
- Python基础之Python语言类型
编程语言主要从以下几个角度进行分类: 编译型和解释型 静态语言和动态语言 强类型定义语言和弱类型定义语言 编译和解释的区别是什么? 编译器把源程序的每一条语句都编译成机器语言,并保存成二进制文件,这样 ...
- linux命令---vi编辑器快速定位行数
linux命令—vi编辑器快速定位行数.删除当前行.和删除当前行后面的全部内容 1.vi 编辑器如何快速定位到第N行 命令方式下 :n http://bbs.chinaunix.net/thread- ...
- django 网站上传资源的显示与配置
1. 上传资源的配置 1. 首先在项目里创建一个名称叫media的文件夹专门保存用户上传 2. settings.py文件配置上传资源的路径 # 上传资源路径,如果图片,上传文件等 MEDIA_UR ...
- uni-app 尺寸单位
uni-app 支持的通用 css 单位包括 px.rpx px 即屏幕像素 rpx 即响应式px,一种根据屏幕宽度自适应的动态单位.以750宽的屏幕为基准,750rpx恰好为屏幕宽度.屏幕变宽,rp ...
- mysql统计前24小时数据没有补0
SELECT t1. HOUR HOUR, COUNT(t2. HOUR) count FROM ( SELECT DATE_FORMAT( HOUR), '%y-%m-%d %H' ) HOUR F ...