使用JavaScript调用本地打印机

https://blog.csdn.net/zZZxiaozhi/article/details/117062010

# HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p id="xz">This is Printer!</p>
    <button onclick="printer()">打印</button>
</body>
</html>
# js代码
function printer(){
    var newWin = window.open('printer', '', '');
    var xiaozhi = document.getElementById("xz").innerText;   // 这里的id是要打印的标签里的id
	// innerHtml  .innerHTML
    newWin.document.write(xiaozhi);
    newWin.document.location.reload();
    newWin.print();
    newWin.close();
}

其他参考print 文件
https://blog.csdn.net/m0_72416767/article/details/127525980

https://blog.csdn.net/q1424966670/article/details/119786095

posted @ 2023-03-30 13:09  寒冷的雨呢  阅读(1603)  评论(0编辑  收藏  举报