ใช้แอตทริบิวต์ onbeforeprint เพื่อรันสคริปต์ก่อนที่เอกสารจะถูกพิมพ์ใน HTML
ตัวอย่าง
ลองรันโค้ดด้านล่างเพื่อใช้งานแอตทริบิวต์ onbeforeprint:
<!DOCTYPE html>
<html>
<body onbeforeprint="display()">
<script>
function display() {
alert("The document will now print.");
}
</script>
</body>
</html>