0

I have a function using window.print() to print the current page. I want to remove page URL when print page. I want to remove the following URL

enter image description here

Here is my code, I want to remove it in this function

print() {
    this.isPrint = true;
    document.title = "";
    setTimeout(() => {
        window.print();
    }, 0);
}
Shohel
  • 3,886
  • 4
  • 38
  • 75
  • This should help https://stackoverflow.com/questions/8228088/remove-header-and-footer-from-window-print – Sumit Surana Apr 12 '19 at 04:33
  • Possible duplicate of [Remove header and footer from window.print()](https://stackoverflow.com/questions/8228088/remove-header-and-footer-from-window-print) – Smokey Dawson Apr 12 '19 at 04:41

2 Answers2

0

add css

 @page { size: auto;  margin: 0mm; }
Hrishi
  • 1,210
  • 1
  • 13
  • 25
0

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/

Shohel
  • 3,886
  • 4
  • 38
  • 75