How to set the page height when using window.print?

Viewed 2109

I want to print a page via pos printer, but now it prints too long blank page. Here is my js code.

<script>
  $("#print").click( function (){
      var div_height = document.getElementById("yu_jie_dan").clientHeight;
      var printContents = document.getElementById("yu_jie_dan").innerHTML;
      w = window.open("", 'name', 'resizable=1',false);
      w.document.write("<body style='width: 230px;font-size: 30px;'>");
      w.document.write(printContents);
      w.document.write("</body>");
      w.print();
      w.close();
  })
</script>

I want to set my page width to 230px and the height is auto.

2 Answers
Related