【发布时间】:2019-10-21 14:59:04
【问题描述】:
我正在使用 window.print 方法在屏幕下方打印。现在我想隐藏日期(图像和标题的左上角(不是大标题),由于某种原因我已经模糊了)。
我读过文章,上面写着@pages { margin: 0 }
但我不确定如何将其应用于 window.print();
我尝试过使用setAttribute(),但它没有帮助,或者我可能犯了一些错误
const element = document.getElementById("qr-code").innerHTML;
var printWindow = window.open('', '', 'height=800,width=800');
printWindow.document.write(element);
printWindow.document.close();
const title = printWindow.document.title = "some title here";
const heading = printWindow.document.createElement('h1');
const text = printWindow.document.createTextNode(title);
heading.appendChild(text);
heading.setAttribute('style', 'order: -1; margin-bottom: 50px;');
printWindow.document.body.appendChild(heading);
printWindow.document.body.setAttribute('style', 'display: grid; width: 100%; justify-items: center; margin: 0;');
printWindow.print();
【问题讨论】:
-
你能在这里显示相关的代码吗?除非我们看到这一点,否则我们将无法真正提供帮助。您可以在发布之前更改任何我们看不到的信息。
-
嗨 @AndrewLohr 用代码编辑
标签: javascript css vue.js