HTML - attributes - onbeforeprint

revision:


Content

"onbeforeprint" attribute: before printing or before opening print dialogue syntax some examples


"onbeforeprint" attribute: before printing or before opening print dialogue

top

The attribute fires when a page is about to be printed or before the print dialogue box appears. The onbeforeprint attribute is often used together with the onafterprint attribute.
The onbeforeprint attribute is part of the <event attributes> and can be used on the following element:<body>.


syntax

top

<element onbeforeprint="script"></element>

script: the script to be run on onbeforeprint


some examples

top

Try to print this document

Keyboard shortcuts, such as Ctrl+P sets the page to print.

codes:
                    <body onbeforeprint="myFunction()">
                        <h4>Try to print this document</h4>
                        <p class="spec">Keyboard shortcuts, such as Ctrl+P sets the page to print.</p>
                    </body>
                    <script>
                        function myFunction() {
                            alert("You are about to print this document!");
                        }
                    </script>