index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<button onclick="clickHandler()">print</button>
<script>
function clickHandler() {
if (typeof window.print === "function") {
window.print();
} else {
alert("您的设备不支持打印操作");
}
}
</script>
</body>
</html>