aboutsummaryrefslogtreecommitdiff
path: root/files/uk/web/api/urlsearchparams/index.html
blob: 78ab36b8e8dd5ba4d614de7d3517bf4fde34d379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
title: URLSearchParams
slug: Web/API/URLSearchParams
translation_of: Web/API/URLSearchParams
---
<p>{{ApiRef("URL API")}}</p>

<p><strong><code>URLSearchParams</code></strong> інтерфейс визначає корисні методи для роботи з довгими текстовими URL.</p>

<p>Об'єктна реалізація <code>URLSearchParams</code> може використовуватись напряму в {{jsxref("Statements/for...of", "for...of")}} структурі, замість {{domxref('URLSearchParams.entries()', 'entries()')}}: <code>for (var p of mySearchParams)</code> що еквівалентно до <code>for (var p of mySearchParams.entries())</code>.</p>

<h2 id="Конструктор">Конструктор</h2>

<dl>
 <dt>{{domxref("URLSearchParams.URLSearchParams", 'URLSearchParams()')}}</dt>
 <dd>Конструктор вертає <code>URLSearchParams</code> об'єкт.</dd>
</dl>

<h2 id="Properties">Properties</h2>

<p><em>This interface doesn't inherit any property.</em></p>

<h2 id="Методи">Методи</h2>

<p><em>Інтерфейс на наслідує ніяких методів</em></p>

<dl>
 <dt>{{domxref("URLSearchParams.append()")}}</dt>
 <dd>Appends a specified key/value pair as a new search parameter.</dd>
 <dt>{{domxref("URLSearchParams.delete()")}}</dt>
 <dd>Deletes the given search parameter, and its associated value, from the list of all search parameters.</dd>
 <dt>{{domxref("URLSearchParams.entries()")}}</dt>
 <dd>Returns an {{jsxref("Iteration_protocols","iterator")}} allowing to go through all key/value pairs contained in this object.</dd>
 <dt>{{domxref("URLSearchParams.get()")}}</dt>
 <dd>Returns the first value associated to the given search parameter.</dd>
 <dt>{{domxref("URLSearchParams.getAll()")}}</dt>
 <dd>Returns all the values association with a given search parameter.</dd>
 <dt>{{domxref("URLSearchParams.has()")}}</dt>
 <dd>Returns a {{jsxref("Boolean")}} indicating if such a search parameter exists.</dd>
 <dt>{{domxref("URLSearchParams.keys()")}}</dt>
 <dd>Returns an {{jsxref("Iteration_protocols", "iterator")}} allowing to go through all <strong>keys </strong>of the key/value pairs contained in this object.</dd>
 <dt>{{domxref("URLSearchParams.set()")}}</dt>
 <dd>Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.</dd>
 <dt>{{domxref("URLSearchParams.toString()")}}</dt>
 <dd>Returns a string containg a query string suitable for use in a URL.</dd>
 <dt>{{domxref("URLSearchParams.values()")}}</dt>
 <dd>Returns an {{jsxref("Iteration_protocols", "iterator")}} allowing to go through all <strong>values </strong>of the key/value pairs contained in this object.</dd>
</dl>

<h2 id="Example">Example</h2>

<pre class="brush: js notranslate">var paramsString = "q=URLUtils.searchParams&amp;topic=api"
var searchParams = new URLSearchParams(paramsString);

//Iterate the search parameters.
for (let p of searchParams) {
  console.log(p);
}

searchParams.has("topic") === true; // true
searchParams.get("topic") === "api"; // true
searchParams.getAll("topic"); // ["api"]
searchParams.get("foo") === null; // true
searchParams.append("topic", "webdev");
searchParams.toString(); // "q=URLUtils.searchParams&amp;topic=api&amp;topic=webdev"
searchParams.set("topic", "More webdev");
searchParams.toString(); // "q=URLUtils.searchParams&amp;topic=More+webdev"
searchParams.delete("topic");
searchParams.toString(); // "q=URLUtils.searchParams"
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('URL', '#urlsearchparams', "URLSearchParams")}}</td>
   <td>{{Spec2('URL')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(49)}}</td>
   <td>{{CompatGeckoDesktop("29.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>36</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>entries()</code>, <code>keys()</code>, <code>values()</code>, and support of <code>for...of</code></td>
   <td>{{CompatChrome(49)}}</td>
   <td>{{CompatGeckoDesktop("44.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>36</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49)}}</td>
   <td>{{CompatGeckoMobile("29.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49)}}</td>
  </tr>
  <tr>
   <td><code>entries()</code>, <code>keys()</code>, <code>values()</code>, and support of <code>for...of</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49)}}</td>
   <td>{{CompatGeckoMobile("44.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49)}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>Other URL-related interfaces: {{domxref("URL")}}, {{domxref("URLUtils")}}.</li>
 <li><a href="https://developers.google.com/web/updates/2016/01/urlsearchparams?hl=en">Google Developers: Easy URL manipulation with URLSearchParams</a></li>
</ul>

<dl>
</dl>