The A complete, encoded Uniform Resource Identifier. A new string representing the unencoded version of the given encoded Uniform Resource Identifier [URI]. Throws an Replaces each escape sequence in the encoded URI with the character that it represents, but does not decode escape sequences that could not have been introduced by decodeURI[]
function decodes a Uniform Resource Identifier [URI] previously created by encodeURI[]
or by a similar routine. Try it
Syntax
Parameters
encodedURI
Return value
Exceptions
URIError
["malformed URI sequence"] exception when encodedURI
contains invalid character sequences. Description
encodeURI
. The character
#
is not decoded from escape sequences. Examples
Decoding a Cyrillic URL
decodeURI['//developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'];
// "//developer.mozilla.org/ru/docs/JavaScript_шеллы"
Catching errors
try {
const a = decodeURI['%E0%A4%A'];
} catch [e] {
console.error[e];
}
// URIError: malformed URI sequence
Specifications
ECMAScript Language Specification # sec-decodeuri-encodeduri |
Browser compatibility
BCD tables only load in the browser
See also
The decodeURIComponent[]
function decodes a Uniform Resource Identifier [URI] component previously created by encodeURIComponent
or by a similar routine. Try it
Syntax
decodeURIComponent[encodedURI]
Parameters
encodedURI
An encoded component of a Uniform Resource Identifier.
Return value
A new string representing the decoded version of the given encoded Uniform Resource Identifier [URI] component.
Exceptions
Throws an URIError
["malformed URI sequence"] exception when used wrongly.
Description
Replaces each escape sequence in the encoded URI component with the character that it represents.
Examples
Decoding a Cyrillic URL component
decodeURIComponent['JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'];
// "JavaScript_шеллы"
Catching errors
try {
const a = decodeURIComponent['%E0%A4%A'];
} catch [e] {
console.error[e];
}
// URIError: malformed URI sequence
Decoding query parameters from a URL
decodeURIComponent cannot be used directly to parse query parameters from a URL. It needs a bit of preparation.
function decodeQueryParam[p] {
return decodeURIComponent[p.replace[/\+/g, ' ']];
}
decodeQueryParam['search+query%20%28correct%29'];
// 'search query [correct]'
Specifications
ECMAScript Language Specification # sec-decodeuricomponent-encodeduricomponent |
Browser compatibility
BCD tables only load in the browser
See also
Example
Decode a URI after encoding it:
let uri = "my test.asp?name=ståle&car=saab";
let encoded = encodeURI[uri];
let decoded = decodeURI[encoded];
Try it Yourself »
Definition and Usage
The decodeURI[]
method decodes a URI.
Syntax
Parameters
Parameter | Description |
uri | Required. The URI to decode. |
Return Value
Type | Description |
A string | The decoded URI. |
Browser Support
decodeURI[]
is an ECMAScript1 [ES1] feature.
ES1 [JavaScript 1997] is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |