The JavaScript decodeURI Function

The JavaScript decodeURI function is a global function that decodes a string previously encoded using the encodeURI function.

Syntax

var decoded_uri = decodeURI(encoded_uri);

Parameters

encoded_uri
A complete encoded URI

Description

decodeURI() returns a decoded URI by replacing each UTF-8 escape sequence with the character that it represents.

Example:

decodeURI('~!@#$%25%5E&*()=+%5B%5D%7B%7D%5C;:\'%22,/?');

Output:

~!@#$%^&*()=+[]{}\;:'",/?

JavaScript decodeURI Examples

The JavaScript decodeURI function can be used to decode special reserved characters and other non-ASCII characters such as letters with diacritics or from the Cyrillic alphabet.

Decoding letters with diacritics

Here's an example of decoding a URI that contains letters with diacritics:

decodeURI("http://en.wikipedia.org/wiki/Bj%C3%B6rk_Gu%C3%B0mundsd%C3%B3ttir");

The output of the above code will be:

http://en.wikipedia.org/wiki/Björk_Guðmundsdóttir

Decoding Cyrillic letters

Below is an example of decoding a URI that contains Cyrillic letters:

decodeURI("http://en.wikipedia.org/wiki/%D0%90%D0%BB%D0%B5%D0%BA%D1%81%D0%B5%D0%B9");

The above code will yield:

http://en.wikipedia.org/wiki/Алексей

See also

If you see a typo, want to make a suggestion or have anything in particular you'd like to know more about, please drop us an e-mail at hello at diveintojavascript dot com.

Copyright © 2010-2013 Dive Into JavaScript