HTMLonbeforeprintイベント属性
HTML onbeforeprintイベント属性は、ページが印刷されようとしているとき、または印刷ダイアログボックスがHTMLドキュメントに表示される前にトリガーされます。
構文
以下は構文です-
<tagname onbeforeprint=”script”></tagname>
HTMLonbeforeprintイベント属性の例を見てみましょう-
例
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background-color: #FBAB7E;
background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
text-align: center;
padding: 20px;
}
p {
font-size: 1.1rem;
}
</style>
</head>
<body onbeforeprint="get()">
<h1>HTML onbeforeprint Event Attribute Demo</h1>
<p>I'm a paragraph HTML element with some dummy text.</p>
<p style="color:#db133a;">Now try to print this document.</p>
<div class="show"></div>
<script>
function get() {
document.body.style.background = "lightblue";
}
</script>
</body>
</html> 出力
次に、ctrl + pを使用してドキュメントを印刷し、onbeforeprintイベント属性がどのように機能するかを観察します。
-
HTMLondragendイベント属性
HTML ondragendイベント属性は、ユーザーがHTMLドキュメント内のHTML要素の要素またはテキストのドラッグを終了したときにトリガーされます。 構文 以下は構文です- <tagname ondragend=”script”></tagname> HTMLオンドラッグイベント属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <head> <style> body { color: #000;
-
HTMLonpageshowイベント属性
HTML onpageshowイベント属性は、ユーザーがWebページに移動したときにトリガーされます。 構文 以下は構文です- <body onpageshow=”script”></body> HTMLonpageshowイベント属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <style> body { color: #000; height: 100vh; &nb