The JavaScript decodeURI function is a global function that decodes a string previously encoded using the encodeURI function.
var decoded_uri = decodeURI(encoded_uri);encoded_uridecodeURI() 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:
~!@#$%^&*()=+[]{}\;:'",/?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.
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óttirBelow 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/Алексей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-2011 Dive Into JavaScript