--- title: HTMLElement.onpaste slug: Web/API/HTMLElement/onpaste tags: - API - API - HTMLElement - HTMLElement - イベントハンドラー - イベントハンドラー - プロパティ - プロパティ - リファレンス - 標準外 translation_of: Web/API/HTMLElement/onpaste ---
onpaste プロパティは、現在の要素の onPaste イベントハンドラーを返します。 {{event("paste")}} の W3C 草稿を参照してください。
element.onpaste = functionRef;
ここでの functionRef は関数です。それはたいてい、他の場所で宣言された関数の名前、あるいは function 式です。詳しくは JavaScript リファレンス:Functions を参照してください。
<!DOCTYPE html>
<html>
<head>
<title>onpaste event example</title>
</head>
<body>
<h1>Play with this editor!</h1>
<textarea id="editor" rows="3" cols="80">
Try pasting text into this area!
</textarea>
<script>
function log(txt) {
document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
}
function pasteIntercept(evt) {
log("Pasting!");
}
document.getElementById("editor").addEventListener("paste", pasteIntercept, false);
</script>
<h2>Log</h2>
<textarea rows="15" cols="80" id="log" readonly="true"></textarea>
</body>
</html>
この例は、テキストエリアへの貼り付けのログを表示します。
このイベントは、ユーザがテキストを貼り付けしようとしたときに発生します。
Firefox 13 から、この機能は設定 dom.event.clipboardevents.enabled で制御されます。既定値は true ですが無効化できます。
仕様の一部ではありません。
現在、 DOM だけでペーストされたテキストを得る方法はありません。その情報を得るためには {{ Interface("nsIClipboard") }} を用いる必要があります。
{{Compat("api.HTMLElement.onpaste")}}