在将文档以HTML格式打印之前,请使用 onbeforeprint 属性执行脚本。
您可以尝试运行以下代码以实现onbeforeprint属性-
<!DOCTYPE html>
<html>
<body onbeforeprint = "display()">
<script>
function display() {
alert("现在将打印文档。");
}
</script>
</body>
</html>