Javascript decodeURIComponent()

Introduction

The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component created by encodeURIComponent().

decodeURIComponent(encodedURI)
Parameters Meaning
encodedURIAn encoded component of a URI.

Decoding a URL component

let a = decodeURIComponent('%D1%88%D0%B5');
console.log(a);

Catching errors

try {/*from w  w w.j  a  v  a 2  s .c  o  m*/
    let a = decodeURIComponent('%D1%88%D0%B5');
    console.log(a);
} catch(e) {
  console.error(e);
}

decodeURIComponent() decodes all characters encoded by encodeURIComponent().

let uri = "http%3A%2F%2Fwww.java2s.com%2Fillegal%20value.js%23start";
console.log(decodeURI(uri));/* w  w w .j  a va2 s .  c o m*/
console.log(decodeURIComponent(uri));

The URI methods encodeURI(), encodeURIComponent(), decodeURI(), and decodeURIComponent() replace the escape() and unescape() methods, which are deprecated in the ECMA-262 third edition.




PreviousNext

Related