javascript - Mozilla Firefox 打印模态数据以及要打印的 div
问题描述
```
<div class="maindiv></div>
<div class="printablediv"></div>
function printData()
{
$('#ProductIdModal').modal('hide');
$(".maindiv").css('display','none');
$(".Printablediv").css('display','block');
$('.modal-backdrop').remove();
window.print();
}
window.addEventListener("afterprint", myFunction);
function myFunction() {
$(".maindiv").css('display','block');
$(".Printablediv").css('display','none');
}
```
我写了一个函数来打印一个名为 printData() 的 Ajax 成功的 div。Ajax 调用是从名为 ProductModal 的模式上的按钮进行的
我在 chrome 中获得的打印预览很好,但模态显示在 div 下方的 mozilla firefox 中。
解决方案
尝试使用印刷媒体查询。对于您的情况,我不确定您是否需要将样式应用于页面或模式。
这些 CSS 样式仅在打印时自动应用,即使通过浏览器也是如此。您可以更改样式或隐藏内容。
/* print styles. put these at the end of your css. */
@media print {
/* some of yours, copied from the js function: */
.modal { display: none; }
.maindiv { display: none; }
.Printablediv { display: block; }
/* other. */
* { color:#333; }
html { height:auto; }
.otherThing { font-size: 20pt; }
}
希望有效。
推荐阅读
- oop - XML 配置的 OO 设计模式
- python - 用特定变量替换 null
- tfs - 内部 TFS 中是否提供构建管道触发器
- actions-on-google - Action on Google 用户查询的时长是否有限制?
- sql - 列出 SQL Server 中所有删除的数据库
- sql - 选择 ID 范围 SQL Server 之间的总和
- sql - SQL - 连接多个表
- r - R - svyciprop 不能仅与集群中的两个组一起使用
- json - 抓取 JSON 并将其映射到对象
- amazon-web-services - 在 AWS Query 中列出 EBS VolumeID 和 Instance ID