Global decodeURIComponent() Function - Javascript Global

Javascript examples for Global:decodeURIComponent

Description

The decodeURIComponent() function decodes a URI component.

Parameter Values

Parameter Description
uri Required. The URI to be decoded

Return Value:

A String, representing the decoded URI

Decode a URI after encoding it:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w  w  w. ja v a 2s. c o  m*/
    var uri = "https://example.com/my test.asp?name=st?le&car=saab";
    var uri_enc = encodeURIComponent(uri);
    var uri_dec = decodeURIComponent(uri_enc);
    var res = "Encoded URI: " + uri_enc + "<br>" + "Decoded URI: " + uri_dec;
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials