From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/htmlelement/oncopy/index.html | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 files/ja/web/api/htmlelement/oncopy/index.html (limited to 'files/ja/web/api/htmlelement/oncopy') diff --git a/files/ja/web/api/htmlelement/oncopy/index.html b/files/ja/web/api/htmlelement/oncopy/index.html new file mode 100644 index 0000000000..52f3c816f6 --- /dev/null +++ b/files/ja/web/api/htmlelement/oncopy/index.html @@ -0,0 +1,85 @@ +--- +title: HTMLElement.oncopy +slug: Web/API/HTMLElement/oncopy +tags: + - API + - Event Handler + - Experimental + - HTMLElement + - NeedsSpecTable + - Property + - Reference +translation_of: Web/API/HTMLElement/oncopy +--- +
{{ APIRef("HTML DOM") }}{{SeeCompatTable}} {{ Fx_minversion_header(3) }}
+ +

oncopy プロパティは {{domxref("HTMLElement")}} インターフェイスのプロパティで、 {{domxref("Element/copy_event", "copy")}} イベントを処理するイベントハンドラー ({{domxref("EventHandler")}}) です。

+ +

copy イベントはユーザーがテキストをコピーしようとしたときに発生します。

+ +

構文

+ +
target.oncopy = functionRef;
+ +

+ +

functionRef は関数名または関数式です。この関数は {{domxref("ClipboardEvent")}} オブジェクトを唯一の引数として受け取ります。

+ +

+ +

この例では、 {{htmlElement("textarea")}} からのすべてのコピーと貼り付けをブロックします。

+ +

HTML

+ +
<h3>Play with this text area:</h3>
+<textarea id="editor" rows="3">Try copying and pasting text into this field!</textarea>
+
+<h3>Log:</h3>
+<p id="log"></p>
+ +

JavaScript

+ +
const log = document.getElementById('log');
+
+function logCopy(event) {
+  log.innerText = 'Copy blocked!\n' + log.innerText;
+  event.preventDefault();
+}
+
+function logPaste(event) {
+  log.innerText = 'Paste blocked!\n' + log.innerText;
+  event.preventDefault();
+}
+
+const editor = document.getElementById('editor');
+
+editor.oncopy = logCopy;
+editor.onpaste = logPaste;
+ +

結果

+ +

{{EmbedLiveSample("Example", 700, 300)}}

+ +

仕様書

+ +

WHATWG Standard

+ +

ブラウザーの互換性

+ + + +

{{Compat("api.HTMLElement.oncopy")}}

+ +

Firefox 13 から、この機能は設定 dom.event.clipboardevents.enabled で制御されます。既定値は true ですが無効化できます。

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf