仅提供思路,勿喷如下↓


 /**
* 打印方法
* @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新开窗口预览打印处理的方式的更多相关文章

  1. Vue.js 3.0 新特性预览

    总结起来,Vue 3 以下方面值得我们期待 : 更快 更小 更易于维护 更多的原生支持 更易于开发使用 完整的PPT:docs.google.com/presentatio… Evan 和 Vue 团 ...

  2. 基于Three.js的360X180度全景图预览插件

    基于Three.js的360X180度全景图预览插件 时间 2015-08-12 10:01:10  HTML5中国 原文  http://www.html5cn.org/article-8621-1 ...

  3. js实现图片上传预览及进度条

    原文js实现图片上传预览及进度条 最近在做图片上传的时候,由于产品设计的比较fashion,上网找了比较久还没有现成的,因此自己做了一个,实现的功能如下: 1:去除浏览器<input type= ...

  4. js实现移动端图片预览:手势缩放, 手势拖动,双击放大...

    .katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...

  5. C# 9.0 新特性预览 - 类型推导的 new

    C# 9.0 新特性预览 - 类型推导的 new 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大 ...

  6. C# 9.0 新特性预览 - 空参数校验

    C# 9.0 新特性预览 - 空参数校验 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它 ...

  7. C# 9.0 新特性预览 - 顶级语句

    C# 9.0 新特性预览 - 顶级语句 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它们 ...

  8. C# 9.0 新特性预览 - init-only 属性

    C# 9.0 新特性预览 - init-only 属性 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章 ...

  9. 20天等待,申请终于通过,安装和体验IntelliJ IDEA新UI预览版

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于IDEA的预览版 IDEA会启用新的UI,这事情之 ...

随机推荐

  1. 鸟哥linux私房菜第6章笔记

    鸟哥linux私房菜第6章笔记 文件权限 修改 chgrp [-R] groupname filename //修改文件所属组 chown [-R] ownername[:groupname] fil ...

  2. JS单线程和异步

    线程和单线程的概念: 线程:是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同 ...

  3. 【bug解决】ios微信浏览器中背景音乐无法播放

    我记得之前在一次项目中,出现过浏览报错: 当时的文档链接如右:[解决]HTML5新标签audio的autoplay自动播放属性失效的解决方案 所以在这次H5的制作中,我使用了iframe来加载音频文件 ...

  4. Subarray Sorting (线段树)

    题意:给你两个长度为 n 的序列 a 和 b , 可以对 a 进行 操作: 选择一段区间[ l, r ] ,使得序列a 在这段区间里 按升序排序. 可以对a 进行任意多次操作,问 a是否有可能变成b序 ...

  5. easyUI datagrid中checkbox选中事件以及行点击事件,翻页之后还可以选中

    DataGrid其中与选择,勾选相关 DataGrid属性:singleSelect boolean 如果为true,则只允许选择一行. false ctrlSelect boolean 在启用多行选 ...

  6. Java线程之ThreadLocal

    翻译:https://www.journaldev.com/1076/java-threadlocal-example?utm_source=website&utm_medium=sideba ...

  7. Xshell安装教程及Xshell安装程序集组件时出错的解决方法

    部分小伙伴在安装Xshell的时候可能会遇到这个问题:“Xshell5安装程序集组件{0D7E67F6-1A6A-3A26-AF95-B8E83DDCCC3F}时出错.HRESULT0x80070BC ...

  8. 三、Reids(高性能)key-value服务器知识整合

    一.Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. 知识链接:https://www.runoob.com/redis/redis-backup.html ht ...

  9. shiro 不使用加密 解决 org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.sh

    测试本方法为失效的 报错: org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token ...

  10. LeetCode 230. 二叉搜索树中第K小的元素(Kth Smallest Element in a BST)

    题目描述 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素. 说明:你可以假设 k 总是有效的,1 ≤ k ≤ 二叉搜索树元素个数. 示例 1: 输入: roo ...