What is decodeuri in javascript?

The decodeURI() function decodes a Uniform Resource Identifier (URI) previously created by encodeURI() or by a similar routine.

Try it

Syntax

Parameters

encodedURI

A complete, encoded Uniform Resource Identifier.

Return value

A new string representing the unencoded version of the given encoded Uniform Resource Identifier (URI).

Exceptions

Throws an URIError ("malformed URI sequence") exception when encodedURI contains invalid character sequences.

Description

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 encodeURI. The character # is not decoded from escape sequences.

Examples

Decoding a Cyrillic URL

decodeURI('https://developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B');
// "https://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

Specification
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

Specification
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


What is Javascript decodeURI?

The decodeURI() function decodes a Uniform Resource Identifier (URI) previously created by encodeURI() or by a similar routine.

What is encodeURI and decodeURI in Javascript?

The encodeURI() function encodes the complete URI including special characters except except (, / ? : @ & = + $ #) characters. The decodeURI() function decodes the URI generated by the encodeURI() function.

What is difference between decodeURI and decodeURIComponent?

decodeURI is used to decode complete URIs that have been encoded using encodeURI . Another similar function is decodeURIComponent . The difference is that the decodeURIComponent is used to decode a part of the URI and not the complete URI.

How do I decode encodeURI?

1. decodeURI function: The decodeURI() function is used to decode URI generated by encodeURI(). Parameters: This function accepts a single parameter complete_encoded_uri_string which holds the encoded string. Return Value: This function returns the decoded string (original string).