/

HTML / CSS / JavaScript Tutorial

JavaScript Global method: decodeURI()

[this page | pdf | back links]

The JavaScript Global decodeURI() method inverts the outcome of encoding a string using encodeURI. It is depreciated, and decodeURI or decodeURIComponent should be used instead.

 

It has the following syntax with the following parameters:

 

decodeURI(encodedURI)

 

Parameter

Required / Optional

Description

encodedURI

Required

String representing an encoded URI

 

More detail on URI encoding is given here.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse :collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="ExampleE"></code></td>
<td><code id="ResultE"></code></td>
</tr>
<tr>
<td><code id="ExampleEC"></code></td>
<td><code id="ResultEC"></code></td>
</tr>
<tr>
<tr>
<td><code id="ExampleD"></code></td>
<td><code id="ResultD"></code></td>
</tr>
<tr>
<td><code id="ExampleDC"></code></td>
<td><code id="ResultDC"></code></td>
</tr>
<tr>
<td><code id="ExampleEscape"></code></td>
<td><code id="ResultEscape"></code></td>
</tr>
<tr>
<td><code id="ExampleUnescape"></code></td>
<td><code id="ResultUnescape"></code></td>
</tr>
</table>

<script>
document.getElementById("ExampleE").innerHTML =
  'var x = encodeURI("a1!%?");';
document.getElementById("ResultE").innerHTML =
  encodeURI("a1!%?");
document.getElementById("ExampleEC").innerHTML =
  'var x = encodeURIComponent("a1!%?");';
document.getElementById("ResultEC").innerHTML =
  encodeURIComponent("a1!%?");
document.getElementById("ExampleD").innerHTML =
  'var x = decodeURI("a1!%25?");';
document.getElementById("ResultD").innerHTML =
  decodeURI("a1!%25?");
document.getElementById("ExampleDC").innerHTML =
  'var x = decodeURIComponent("a1!%25%3F");';
document.getElementById("ResultDC").innerHTML =
  decodeURIComponent("a1!%25%3F");
document.getElementById("ExampleEscape").innerHTML =
  '(depreciated)<br>var x = encape("a1!%?");';
document.getElementById("ResultEscape").innerHTML =
  escape("a1!%?");
document.getElementById("ExampleUnescape").innerHTML =
  '(depreciated)<br>var x = unescape("a1%21%25%3F");';
document.getElementById("ResultUnescape").innerHTML =
  unescape("a1!%25?");
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodGlobalDecodeURI() {
  return (decodeURI("%25?") == "%?");
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile