如何通过JavaScript或CSS取消浏览器设置中的页首及页尾的默认勾选?-灵析社区

七安前

请问要如何设置浏览器如下设置中的【页首及页尾】,我想要默认不勾选要如何编写JavaScript代码或css样式? 或者通过@media print自定义页首页尾的内容?但是我使用printJS插件打印,似乎@media print的样式对printJS的打印没有效果? ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241013/4d5c310e57900e8d61c32b004a62c12f.png) 以下是我的代码: // 转图片打印 html2canvas(this.$refs.templateToImg, { backgroundColor: null, useCORS: true, windowHeight: document.body.scrollHeight, }).then(canvas => { dom.style.height = 'calc(100vh - 400px)' dom.style.overflow = 'auto' const url = canvas.toDataURL('image/jpg') this.img = url // 下载img 下载是好的,说明图片没问题 // const a = document.createElement('a') // a.href = url // a.download = this.previewTitle() + '.jpg' // a.click() const styles = "@media print { @page {height: 100%;@top-left {content: '页首内容';}@bottom-center {content: '页脚内容';}}}" // 设置了没有效果 printJS({ printable: url, type: 'image', documentTitle: this.previewTitle(), style: styles, onLoadingEnd: () => { this.printLoading = false dom.style.height = 'auto' dom.style.overflow = 'visible' } })

阅读量:155

点赞量:0

问AI
我认为这里已经是浏览器、甚至系统打印机的范畴,所以是无法用 JS、CSS 控制的。