From 362ba6775c2337ed3dc91d5320f7e891c3c74f99 Mon Sep 17 00:00:00 2001 From: MDN Date: Sat, 13 Mar 2021 00:26:44 +0000 Subject: [CRON] sync translated content --- files/ja/_redirects.txt | 2 +- files/ja/_wikihistory.json | 12 +-- files/ja/web/api/document/getselection/index.html | 88 ++++++++++++++++++++++ .../documentorshadowroot/getselection/index.html | 87 --------------------- 4 files changed, 95 insertions(+), 94 deletions(-) create mode 100644 files/ja/web/api/document/getselection/index.html delete mode 100644 files/ja/web/api/documentorshadowroot/getselection/index.html (limited to 'files/ja') diff --git a/files/ja/_redirects.txt b/files/ja/_redirects.txt index afbf74fa1e..6aeb1e8eaa 100644 --- a/files/ja/_redirects.txt +++ b/files/ja/_redirects.txt @@ -3747,12 +3747,12 @@ /ja/docs/Web/API/Document/defaultView/storage_event /ja/docs/Web/API/Window/storage_event /ja/docs/Web/API/Document/domConfig /ja/docs/Web/API/Document /ja/docs/Web/API/Document/elementFromPoint /ja/docs/Web/API/DocumentOrShadowRoot/elementFromPoint -/ja/docs/Web/API/Document/getSelection /ja/docs/conflicting/Web/API/DocumentOrShadowRoot/getSelection /ja/docs/Web/API/Document/inputEncoding /ja/docs/conflicting/Web/API/Document/characterSet /ja/docs/Web/API/Document/onselectionchange /ja/docs/Web/API/GlobalEventHandlers/onselectionchange /ja/docs/Web/API/DocumentOrShadowRoot/activeElement /ja/docs/Web/API/Document/activeElement /ja/docs/Web/API/DocumentOrShadowRoot/fullscreenElement /ja/docs/Web/API/Document/fullscreenElement /ja/docs/Web/API/DocumentOrShadowRoot/getAnimations /ja/docs/Web/API/Document/getAnimations +/ja/docs/Web/API/DocumentOrShadowRoot/getSelection /ja/docs/Web/API/Document/getSelection /ja/docs/Web/API/DocumentOrShadowRoot/msElementsFromRect /ja/docs/orphaned/Web/API/DocumentOrShadowRoot/msElementsFromRect /ja/docs/Web/API/DocumentOrShadowRoot/nodeFromPoint /ja/docs/conflicting/Web/API/DocumentOrShadowRoot /ja/docs/Web/API/DocumentOrShadowRoot/nodesFromPoint /ja/docs/conflicting/Web/API/DocumentOrShadowRoot_20ea0e1d91453a020aad3a16dbce16f1 diff --git a/files/ja/_wikihistory.json b/files/ja/_wikihistory.json index 3da558db6a..565d2b1182 100644 --- a/files/ja/_wikihistory.json +++ b/files/ja/_wikihistory.json @@ -12743,12 +12743,6 @@ "mfuji09" ] }, - "Web/API/DocumentOrShadowRoot/getSelection": { - "modified": "2020-10-15T22:26:08.191Z", - "contributors": [ - "mfuji09" - ] - }, "Web/API/DocumentType": { "modified": "2020-10-15T22:09:56.256Z", "contributors": [ @@ -53496,5 +53490,11 @@ "contributors": [ "eltociear" ] + }, + "Web/API/Document/getSelection": { + "modified": "2020-10-15T22:26:08.191Z", + "contributors": [ + "mfuji09" + ] } } \ No newline at end of file diff --git a/files/ja/web/api/document/getselection/index.html b/files/ja/web/api/document/getselection/index.html new file mode 100644 index 0000000000..81fc970c85 --- /dev/null +++ b/files/ja/web/api/document/getselection/index.html @@ -0,0 +1,88 @@ +--- +title: DocumentOrShadowRoot.getSelection() +slug: Web/API/Document/getSelection +tags: + - API + - DocumentOrShadowRoot + - Doument + - Method + - Reference + - ShadowRoot + - getSelection + - getSelection() + - shadow dom +translation_of: Web/API/DocumentOrShadowRoot/getSelection +original_slug: Web/API/DocumentOrShadowRoot/getSelection +--- +
{{APIRef("DOM")}}{{SeeCompatTable}}
+ +

getSelection() は {{DOMxRef("DocumentOrShadowRoot")}} インターフェイスのプロパティで、ユーザーが選択したテキストの範囲、またはキャレットの現在位置を表す {{DOMxRef("Selection")}} オブジェクトを返します。

+ +

構文

+ +
var selection = documentOrShadowRootInstance.getSelection()
+ +

引数

+ +

なし。

+ +

返値

+ +

{{DOMxRef("Selection")}} オブジェクト。

+ +

+ +
function foo() {
+    var selObj = document.getSelection();
+    alert(selObj);
+    var selRange = selObj.getRangeAt(0);
+    // do stuff with the range
+}
+ +

メモ

+ +

Selection オブジェクトの文字列表現

+ +

JavaScript では、オブジェクトが string を取る関数 ({{DOMxRef("Window.alert()")}} など) に渡された場合、オブジェクトの {{JSxRef("Object.toString", "toString()")}} メソッドが呼び出され、関数にその返値が渡されます。これにより、プロパティやメソッドを持つ実際のオブジェクトであった場合、他の関数に使われると文字列になって現れることがあります。

+ +

上記の例では、 selObj.toString() が呼び出されてから {{DOMxRef("Window.alert()")}} に渡されます。しかし、 JavaScript の String のプロパティやメソッド、例えば lengthsubstr が {{DOMxRef("Selection")}} オブジェクトに対して呼び出されると、そのプロパティやメソッドを持っていないため、エラーが発生するか予期しない結果が返ることがあります。 Selection オブジェクトを文字列として扱うには、 toString() メソッドを直接呼び出してください。

+ +
var selectedText = selObj.toString();
+ + + + + +

{{domxref("Window.getSelection()")}} を呼び出すと、 Document.getSelection() と同等の動作をします。

+ +

Firefox において現在は getSelection() は {{htmlelement("input")}} 要素の中では動作しないことに注意してください。 {{domxref("HTMLInputElement.setSelectionRange()")}}) を使用することで回避できます。

+ +

selectionfocus との違いにも注意してください。 {{domxref("Document.activeElement")}} はフォーカスを持つ要素を返します。

+ +

仕様書

+ + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("Shadow DOM", "#extensions-to-the-documentorshadowroot-mixin", "DocumentOrShadowRoot")}}{{Spec2("Shadow DOM")}}初回定義
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("api.DocumentOrShadowRoot.getSelection")}}

+
diff --git a/files/ja/web/api/documentorshadowroot/getselection/index.html b/files/ja/web/api/documentorshadowroot/getselection/index.html deleted file mode 100644 index e201ed0675..0000000000 --- a/files/ja/web/api/documentorshadowroot/getselection/index.html +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: DocumentOrShadowRoot.getSelection() -slug: Web/API/DocumentOrShadowRoot/getSelection -tags: - - API - - DocumentOrShadowRoot - - Doument - - Method - - Reference - - ShadowRoot - - getSelection - - getSelection() - - shadow dom -translation_of: Web/API/DocumentOrShadowRoot/getSelection ---- -
{{APIRef("DOM")}}{{SeeCompatTable}}
- -

getSelection() は {{DOMxRef("DocumentOrShadowRoot")}} インターフェイスのプロパティで、ユーザーが選択したテキストの範囲、またはキャレットの現在位置を表す {{DOMxRef("Selection")}} オブジェクトを返します。

- -

構文

- -
var selection = documentOrShadowRootInstance.getSelection()
- -

引数

- -

なし。

- -

返値

- -

{{DOMxRef("Selection")}} オブジェクト。

- -

- -
function foo() {
-    var selObj = document.getSelection();
-    alert(selObj);
-    var selRange = selObj.getRangeAt(0);
-    // do stuff with the range
-}
- -

メモ

- -

Selection オブジェクトの文字列表現

- -

JavaScript では、オブジェクトが string を取る関数 ({{DOMxRef("Window.alert()")}} など) に渡された場合、オブジェクトの {{JSxRef("Object.toString", "toString()")}} メソッドが呼び出され、関数にその返値が渡されます。これにより、プロパティやメソッドを持つ実際のオブジェクトであった場合、他の関数に使われると文字列になって現れることがあります。

- -

上記の例では、 selObj.toString() が呼び出されてから {{DOMxRef("Window.alert()")}} に渡されます。しかし、 JavaScript の String のプロパティやメソッド、例えば lengthsubstr が {{DOMxRef("Selection")}} オブジェクトに対して呼び出されると、そのプロパティやメソッドを持っていないため、エラーが発生するか予期しない結果が返ることがあります。 Selection オブジェクトを文字列として扱うには、 toString() メソッドを直接呼び出してください。

- -
var selectedText = selObj.toString();
- - - - - -

{{domxref("Window.getSelection()")}} を呼び出すと、 Document.getSelection() と同等の動作をします。

- -

Firefox において現在は getSelection() は {{htmlelement("input")}} 要素の中では動作しないことに注意してください。 {{domxref("HTMLInputElement.setSelectionRange()")}}) を使用することで回避できます。

- -

selectionfocus との違いにも注意してください。 {{domxref("Document.activeElement")}} はフォーカスを持つ要素を返します。

- -

仕様書

- - - - - - - - - - - - - - -
仕様書状態備考
{{SpecName("Shadow DOM", "#extensions-to-the-documentorshadowroot-mixin", "DocumentOrShadowRoot")}}{{Spec2("Shadow DOM")}}初回定義
- -

ブラウザーの互換性

- -
- - -

{{Compat("api.DocumentOrShadowRoot.getSelection")}}

-
-- cgit v1.2.3-54-g00ecf