I have my html in a php variable say $html and I want to print this html using javascript. I have written following code for this.
<script>var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write(<?= $html ?>);
mywindow.print();</script>
It works for me if variable contains normal string not HTML