--- title: HTMLElement.oncut slug: Web/API/HTMLElement/oncut tags: - API - Event Handler - Experimental - HTMLElement - NeedsSpecTable - Property - Reference browser-compat: api.HTMLElement.oncut translation_of: Web/API/HTMLElement/oncut --- <div>{{ APIRef("HTML DOM") }} {{SeeCompatTable}}</div> <p><code><strong>HTMLElement.oncut</strong></code> は {{domxref("HTMLElement")}} インターフェイスのプロパティで、 {{event("cut")}} イベントを処理する<a href="/ja/docs/Web/Events/Event_handlers">イベントハンドラー</a>です。</p> <p><code>cut</code> イベントは、ユーザーがテキストを切り取りしようとしたときに発行されます。</p> <h2 id="Syntax">構文</h2> <pre class="brush: js"><em>target</em>.oncut = <em>functionRef</em>; </pre> <h3 id="Value">値</h3> <p><code>functionRef</code> は関数名または<a href="/ja/docs/Web/JavaScript/Reference/Operators/function">関数式</a>です。この関数は唯一の引数として {{domxref("ClipboardEvent")}} オブジェクトを受け取ります。</p> <h2 id="Example">例</h2> <p>この例では、テキストを {{htmlElement("textarea")}} からコピーすることはできますが、テキストを切り取りすることはできません。また、コピーと切り取りを仕様としたことをそれぞれ記録します。</p> <h3 id="HTML">HTML</h3> <pre class="brush: html"><h3>このテキストエリアで実行しましょう。</h3> <textarea id="editor" rows="3">このフィールド内のテキストをコピーしたり切り取りしたりしてみましょう。</textarea> <h3>ログ:</h3> <p id="log"></p></pre> <h3 id="JavaScript">JavaScript</h3> <pre class="brush: js">function logCopy(event) { log.innerText = 'Copied!\n' + log.innerText; } function preventCut(event) { event.preventDefault(); log.innerText = 'Cut blocked!\n' + log.innerText; } const editor = document.getElementById('editor'); const log = document.getElementById('log'); editor.oncopy = logCopy; editor.oncut = preventCut;</pre> <h3 id="Result">結果</h3> <p>{{EmbedLiveSample("Example", 700, 300)}}</p> <h2 id="Specifications">仕様書</h2> <p><a href="https://html.spec.whatwg.org/multipage/webappapis.html#handler-oncut">WHATWG 標準</a></p> <h2 id="Browser_compatibility">ブラウザーの互換性</h2> <p>{{Compat}}</p> <p>Firefox 13 以降では、設定項目 <code>dom.event.clipboardevents.enabled</code> でこの機能を制御できます。既定では <code>true</code> になっていますが、無効にすることができます。</p> <h2 id="See_also">関連情報</h2> <ul> <li>クリップボード API イベント {{event("cut")}}</li> <li>関連するイベントハンドラー <ul> <li>{{domxref("HTMLElement.oncopy")}}</li> <li>{{domxref("HTMLElement.onpaste")}}</li> </ul> </li> </ul>