2 Example(s) of Javascript decodeURI functions


Description :

decodeURI function will decode the URI and return the decode string. See the code snippet for decodeURI function.


Javascript decodeURI functions Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="decryptUrl()">Decode URI</button>

<p id="sample"></p>

<script>
function decryptUrl() {
    var uri = "leanKode.com?name=michael&car=voughan";
    var enc = encodeURI(uri);
    var dec = decodeURI(enc);
    var result = "Encoded URI: " + enc + "<br>" + "Decoded URI: " + dec;
    document.getElementById("sample").innerHTML = result;
}
</script>
</body>
</html>

Output

Description :

%20 is a replacement of spaces and decodeURI function will convert all such code to URI. http://learnkode.com/Examples/Javascript/Javascript%20decodeURI%20functions will get converted to http://learnkode.com/Examples/Javascript/Javascript decodeURI functions.


Javascript decodeURI functions Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="decryptUrl()">decodeURI Fucntionality</button>
<p id="sample"></p>
<script>
function decryptUrl() {
       var dec = decodeURI("http://learnkode.com/Examples/Javascript/Javascript%20decodeURI%20functions");
        document.getElementById("sample").innerHTML = dec;
}
</script>

</body>
</html>

Output