HTML onbeforeprint Event Attribute

Description

The event attribute onbeforeprint is triggered after a user requests a print operation (via a menu or a key combination) immediately before a document is printed, as well as when a user requests a print preview. Use the onbeforeprint event to change the document just before printing or before printing. In most cases, this attribute is used to make all information about the document visible immediately before printing.

Syntax

<element onbeforeprint="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>onbeforeprint event</title>
</head>
<body onbeforeprint="test()">
<h1>Try to print this document.</h1>
<p><b>Tip:</b>The keyboard shortcut Ctrl + P prints the page.</p>
<p><b>Note:</b>The onbeforeprint event is supported only in Internet Explorer and Firefox.</p>
<script>
function test() {
    alert("You are about to print this document!");
}
</script>
</body>
</html>

Supported Tags

<body>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
??????