0

I am trying to print the content of my Div.

Below is my js and html code.

function printContent(el){
 var restorepage = document.body.innerHTML;
 var printcontent = document.getElementById(el).innerHTML;
 document.body.innerHTML = printcontent;
 window.print();
 document.body.innerHTML = restorepage;
}
<h1>My page</h1>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
<div id="div2">DIV 2 content...</div>
<button onclick="printContent('div2')">Print Content</button>
<p id="p1">Paragraph 1 content...</p>
<button onclick="printContent('p1')">Print Content</button>

I just want to avoid the print popup so that printing goes directly to default printer.

halfer
  • 19,824
  • 17
  • 99
  • 186
user2828442
  • 2,415
  • 7
  • 57
  • 105
  • 1
    Possible duplicate of [Select a printer and silently print](https://stackoverflow.com/questions/19656372/select-a-printer-and-silently-print) – Ullas Hunka Jul 14 '18 at 10:43

0 Answers0