Javascript decodeURI()

Introduction

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

decodeURI(encodedURI)
Parameters Meaning
encodedURI A complete, encoded Uniform Resource Identifier.

Decoding a URL

let a = decodeURI('https://example.com/%D1%88%D0%B5');
console.log(a);

Catching errors

try {//from   w  ww  .  j  av a 2 s.  c  o  m
  let a = decodeURI('https://example.com/%D1%88%D0%B5');
  console.log(a);
} catch(e) {
  console.error(e);
}

The decodeURI() method decodes characters replaced by using encodeURI().

For instance, %20 is replaced with a space.

let uri = "http%3A%2F%2Fwww.java2s.com%2Fillegal%20value.js%23start";
console.log(decodeURI(uri));/*w w w . j  a  v a 2 s .  c om*/
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