English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tags comprehensive list

HTML5 onbeforeprint event property

When the document associated with the page is about to be printed or previewed for printing, the beforeprint event is triggered.

HTML イベント属性

Online example

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属性と一緒に使用されます

HTML 4.01 HTML5の違い

onbeforeprint属性はHTML5新しい属性。

文法

<element onbeforeprint="script">

属性値

説明
scriptonafterprintで実行されるスクリプト。
HTML イベント属性