简体   繁体   English

如何在javascript或angular 4中使用window.print()打印页面时删除页面URL

[英]How to remove page url when print page with window.print() in javascript or angular 4

I have a function using window.print() to print the current page. 我有一个使用window.print()打印当前页面的函数。 I want to remove page URL when print page. 我想在打印页面时删除页面URL。 I want to remove the following URL 我想删除以下网址

在此输入图像描述

Here is my code, I want to remove it in this function 这是我的代码,我想在此函数中删除它

print() {
    this.isPrint = true;
    document.title = "";
    setTimeout(() => {
        window.print();
    }, 0);
}

添加CSS

 @page { size: auto;  margin: 0mm; }

Try to the following code 尝试以下代码

print() {
  this.isPrint = true;
  document.title = "";
  setTimeout(() => {
    var curURL = window.location.href;
    history.replaceState(history.state, '', '/');
    window.print();
    history.replaceState(history.state, '', curURL);
  }, 0);
}

But this is the perfect way 但这是完美的方式

@media print {
  @page {
    margin: 0;
  }
  body {
    margin: 1.6cm;
  }
}

Or Use printjs https://printjs.crabbly.com/ 或者使用printjs https://printjs.crabbly.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM