Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create html page and print to new tab in javascript

create html page as inline and that page open to new tab and show print view

i tried with this code but not working..

     var mywindow = window.open('', 'Print  Report', 'height=400,width=600');
     mywindow.document.write('<html><head><title>Print  Report</title>');
     mywindow.document.write('</head><body ><table  border="1" style="width: 500px; height: 300px;">');
     mywindow.document.write(htmlTable);
     mywindow.document.write('</table></body></html>');
     mywindow.open().print();
like image 881
Prasanth A R Avatar asked Dec 02 '14 11:12

Prasanth A R


1 Answers

try this..

var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
winPrint.document.write('<title>Print  Report</title><br /><br /> Hellow World');
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close(); 

if the window is not open .. please check whether the popup is blocked :)..

like image 190
Sarath Avatar answered Sep 29 '22 20:09

Sarath