From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/decodeuricomponent/index.html | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/decodeuricomponent/index.html (limited to 'files/ja/web/javascript/reference/global_objects/decodeuricomponent') diff --git a/files/ja/web/javascript/reference/global_objects/decodeuricomponent/index.html b/files/ja/web/javascript/reference/global_objects/decodeuricomponent/index.html new file mode 100644 index 0000000000..9202f63e0b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/decodeuricomponent/index.html @@ -0,0 +1,98 @@ +--- +title: decodeURIComponent() +slug: Web/JavaScript/Reference/Global_Objects/decodeURIComponent +tags: + - JavaScript + - Method + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/decodeURIComponent +--- +
{{jsSidebar("Objects")}}
+ +

decodeURIComponent() 関数は、{{jsxref("encodeURIComponent", "encodeURIComponent()")}} 関数あるいは同様のルーチンによって事前に作成された URI (Uniform Resource Identifier; 統一資源識別子) の構成要素をデコードします。

+ +
{{EmbedInteractiveExample("pages/js/globalprops-decodeuricomponent.html")}}
+ + + +

構文

+ +
decodeURIComponent(encodedURI)
+ +

引数

+ +
+
encodedURI
+
エンコードされた URI の構成要素です。
+
+ +

返値

+ +

エンコードされた統一資源識別子 (URI) の構成要素をデコードしたものを表す新しい文字列です。

+ +

例外

+ +

不正に利用された場合は {{jsxref("URIError")}} ("malformed URI sequence") 例外が発生します。

+ +

解説

+ +

エンコードされた URI の構成要素のエスケープシーケンスを、それぞれが表す文字に置き換えます。

+ +

+ +

キリル文字の URL の構成要素をデコード

+ +
decodeURIComponent('JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B');
+// "JavaScript_шеллы"
+
+ +

エラーの捕捉

+ +
try {
+  var a = decodeURIComponent('%E0%A4%A');
+} catch(e) {
+  console.error(e);
+}
+
+// URIError: malformed URI sequence
+ +

URL からのクエリパラメータのデコード

+ +

decodeURIComponent は、URL からのクエリパラメータを解析するために直接使用することはできません。少し準備が必要です。

+ +
function decodeQueryParam(p) {
+  return decodeURIComponent(p.replace(/\+/g, ' '));
+}
+
+decodeQueryParam('search+query%20%28correct%29');
+// 'search query (correct)'
+
+ +

仕様

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-decodeuricomponent-encodeduricomponent', 'decodeURIComponent')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.decodeURIComponent")}}

+ +

関連情報

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