--- title: window.onselect slug: Web/API/GlobalEventHandlers/onselect tags: - DOM - Gecko - Window translation_of: Web/API/GlobalEventHandlers/onselect --- <div>{{ ApiRef("HTML DOM") }}</div> <p>{{domxref("window")}} の <code>select</code> イベントに対応するイベントハンドラです。</p> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox">window.onselect = <em>funcRef</em>; </pre> <ul> <li><code>funcRef</code> : 関数への参照、または関数式</li> </ul> <h2 id="Example" name="Example">例</h2> <pre class="brush: html"><!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8" /> <title>onselect のテスト</title> <style> .text1 { border: 2px solid red; } </style> <script> window.onselect = selectText; function selectText() { alert("select イベントが発生しました。"); } </script> </head> <body> <textarea class="text1" cols="30" rows="3"> マウスでこのテキストを選択状態にすると onselect イベントが発生し、 アラートを表示する関数が実行されます。 </textarea> </body> </html> </pre> <h2 id="Notes" name="Notes">注記</h2> <p><code>select</code> イベントは、テキストインプット (<code><input type="text"></code>) もしくは {{htmlelement("textarea")}} 要素のテキストが<em>選択された直後に</em> 発生します。</p> <h2 id="Specification" name="Specification">仕様</h2> <table class="spectable standard-table"> <tbody> <tr> <th scope="col">仕様書</th> <th scope="col">策定状況</th> <th scope="col">コメント</th> </tr> <tr> <td>{{SpecName('HTML WHATWG','webappapis.html#handler-onselect','onselect')}}</td> <td>{{Spec2('HTML WHATWG')}}</td> <td> </td> </tr> </tbody> </table> <h2 id="Browser_Compatibility" name="Browser_Compatibility">ブラウザー実装状況</h2> <div> <p>{{Compat("api.GlobalEventHandlers.onselect")}}</p> </div>