English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
When the document associated with the page is about to be printed or previewed for printing, the beforeprint event is triggered.
When the page is to be printed, JavaScript is executed:
<!DOCTYPE html> <html> <head> <title>HTML onbeforeprint event property usage(basic tutorial site w)3codebox.com)</b>/title> <body onbeforeprint="myFunction()"> <h1>Try to print this document</h1> <p><b>Tip:</b>/<b> Keyboard shortcuts, such as Ctrl</b>+P sets the page to print./p> <p><b>Note:</b>/<b> The onbeforeprint event is not supported in Safari and Opera.</b>/p> <script> function myFunction() { alert("You are about to print this document!"); } </script> </body> </html>テストして見てください ‹/›
IEFirefoxOperaChromeSafari
現在、onbeforeprintイベント属性はInternet ExplorerとFirefoxブラウザのみがサポートしています。
ページを印刷する際に(印刷ダイアログが表示される前に)、onbeforeprint属性がトリガーされます。
ヒント: onbeforeprint属性は通常onafterprint属性と一緒に使用されます
onbeforeprint属性はHTML5新しい属性。
<element onbeforeprint="script">
値 | 説明 |
---|---|
script | onafterprintで実行されるスクリプト。 |