我想通过 pos 打印机打印一页,但现在打印的空白页太长。 这是我的 js 代码。
<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>
我想将页面宽度
设置为230px
,高度
为自动
。
最佳答案
css中有一个伪类,只有当你尝试打印html页面时才会生效。
#page-id__or__div-id: print {
// Add style here that you want to see in printed documents
}
关于javascript - 使用window.print时如何设置页面高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45688937/