SYNCERのロゴ
アイキャッチ画像

Window.getSelection() - 選択中のテキスト

getSelection()は、Windowのメソッドです。選択中のテキストを表すSelectionを返します。

概要

名前
getSelection
所属
Window
IDL
Selection? getSelection();
仕様書
http://w3c.github.io/selection-api/#extensions-to-window-interface

説明

引数はありません。Selectionを返します。

デモ

Window.getSelection()のデモです。監視しているので、テキストを選択してみて下さい。

<!-- このコードは編集できます。 -->

<!DOCTYPE html>
<head>
<style>
div#result { white-space: pre-wrap ; }
</style>
</head>
<body>
<p>SYNCER SYNCER SYNCER</p>
<hr>
<div id="result"></div>
<script>
document.onselectionchange = function () {
	var value = getSelection() ;

	console.log( value ) ;
	document.getElementById( "result" ).textContent = value ;
}
</script>
</body>
</html>

サポート状況

ChromeFirefoxSafariEdgeIEOperaiOS SafariAndroid
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年10月14日 (土)
コンテンツを公開しました。