<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The beforeprint Event</h2>
<p>Use the HTML DOM to assign an "onbeforeprint" event to a body element.</p>
<h3>Print this document!</h3>
<p><b>Tip</b>: The keyboard shortcut Ctrl+P prints a page.</p>
<script>
document.getElementsByTagName("body")[0].onbeforeprint = function() {myFunction()};
function myFunction() {
alert("You are about to print this document!");
}
</script>
</body>
</html>