6

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();
Prasanth A R
  • 4,046
  • 9
  • 48
  • 76
  • Works fine in a fiddle: http://jsfiddle.net/c03fqywa/ Can you explain what issues you have? Note that you may need to disable your browsers' popup blocker. – Rory McCrossan Dec 02 '14 at 11:31

2 Answers2

14

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 :)..

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
Sarath
  • 2,318
  • 1
  • 12
  • 24
9

as you need to open a new tab and then make it print .. try this..

<div id="toNewWindow">
    <p>Your content here</p>
</div>
<a href="javascript:;" id="print">Open</a>
<script>
function nWin() {
  var w = window.open();
  var html = $("#toNewWindow").html();

    $(w.document.body).html(html);
    w.print();
}

$(function() {
    $("a#print").click(nWin);
});</script>

fiddle :: http://jsfiddle.net/Sarathv15/8dXvt/420/

Sarath
  • 2,318
  • 1
  • 12
  • 24