非標準
この機能は標準ではなく、標準化の予定もありません。公開されているウェブサイトには使用しないでください。ユーザーによっては使用できないことがあります。実装ごとに大きな差があることもあり、将来は振る舞いが変わるかもしれません。
paste
で W3C Working Draft をご覧ください。概要
onpaste プロパティは、r現在の要素での onPaste イベントハンドラのコードを返します。
構文
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 だけでペーストされたテキストを得る方法はありません。その情報を得るためには nsIClipboard
を用いる必要があります。
メモ
paste
で W3C Working Draft をご覧ください。