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
|
---
title: encodeURI()
slug: Web/JavaScript/Reference/Global_Objects/encodeURI
translation_of: Web/JavaScript/Reference/Global_Objects/encodeURI
---
<div>{{jsSidebar("Objects")}}</div>
<p>Die <code><strong>encodeURI()</strong></code> Funktion kodiert ein Uniform Resource Identifier (Abk. URI, englisch für einheitlicher Bezeichner für Ressurcen), indem sie jedes Vorkommen von speziellen Zeichen durch die jeweilige UTF-8 Zeichenkette ersetzt, die das Zeichen repräsentiert.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox"><code>encodeURI(<em>URI</em>)</code></pre>
<h3 id="Parameter">Parameter</h3>
<dl>
<dt><code>URI</code></dt>
<dd>Ein vollständiger Uniform Resource Identifier.</dd>
</dl>
<h3 id="Return_value">Return value</h3>
<p>Ein neuer String, kodiert als Uniform Resource Identifier (URI).</p>
<h2 id="Beschreibung">Beschreibung</h2>
<p>Die Funktion geht davon aus, dass die URI eine richtige URI ist, sodass sie keine Zeichen kodiert die spezielle Bedeutungen haben.</p>
<p><code>encodeURI</code> ersetzt alle Zeichen <strong>außer </strong>die folgenden<strong> </strong>mit ihrer zugehörigen UTF-8 Escape-Sequenz:</p>
<table class="standard-table">
<tbody>
<tr>
<td class="header">Typ</td>
<td class="header">Beinhaltet</td>
</tr>
<tr>
<td>Zurückgehaltene Zeichen</td>
<td><code>;</code> <code>,</code> <code>/</code> <code>?</code> <code>:</code> <code>@</code> <code>&</code> <code>=</code> <code>+</code> <code>$</code></td>
</tr>
<tr>
<td>Unescapte </td>
<td>alphanumerische Zeichen, <code>-</code> <code>_</code> <code>.</code> <code>!</code> <code>~</code> <code>*</code> <code>'</code> <code>(</code> <code>)</code></td>
</tr>
<tr>
<td>Zeichen für Nummern</td>
<td><code>#</code></td>
</tr>
</tbody>
</table>
<p>Beachten Sie, dass die <code>encodeURI</code> Funktion keine richtigen HTTP GET und POST Requests erzeugen kann, wie für XMLHTTPRequests benötigt, da "&", "+", und "=" nicht kodiert werden. Diese werden in GET und POST als spezielle Zeichen behandelt. Für solche Verwendungen steht die {{jsxref("encodeURIComponent")}} Funktion zur Verfügung.</p>
<p>Beachten Sie auch, dass ein {{jsxref("URIError")}} erzeugt wird, sobald versucht wird, ein <a href="https://de.wikipedia.org/wiki/UTF-16#Kodierung">surrogate</a>, welches nicht zu einem high-low Paar gehört, zu kodieren.</p>
<pre class="brush: js">// high-low paar ok
console.log(encodeURI('\uD800\uDFFF'));
// einzelnes high surrogate erzeugt ein "URIError: malformed URI sequence"
console.log(encodeURI('\uD800'));
// einzelnes low surrogate erzeugt ein "URIError: malformed URI sequence"
console.log(encodeURI('\uDFFF')); </pre>
<p>Wenn Sie den neueren <a href="http://tools.ietf.org/html/rfc3986">RFC3986</a> Standart für URLs benutzen möchten, der eckige Klammern beachtet (für IPv6) und Teile die zur URL gehören könnten (wie der Host) nicht kodiert, könnte der kleine Code-Auszug helfen:</p>
<pre class="brush: js">function fixedEncodeURI(str) {
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}</pre>
<h2 id="Spezifikationen">Spezifikationen</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Spezifikation</th>
<th scope="col">Status</th>
<th scope="col">Kommentar</th>
</tr>
<tr>
<td>{{SpecName('ES3')}}</td>
<td>{{Spec2('ES3')}}</td>
<td>Initial definition.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.1.3.3', 'encodeURI')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-encodeuri-uri', 'encodeURI')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-encodeuri-uri', 'encodeURI')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browser_kompatibilität">Browser kompatibilität</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>Normale Unterstützung</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>
<p>Normale Unterstützung</p>
</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li>{{jsxref("decodeURI")}}</li>
<li>{{jsxref("encodeURIComponent")}}</li>
<li>{{jsxref("decodeURIComponent")}}</li>
</ul>
|