How to decode a URL using JavaScript function?

JavascriptWeb DevelopmentFront End Technology

To decode a URL in JavaScript, use the decodeURI() method.


You can try to run the following code to decode a URL −

<!DOCTYPE html>
      <button onclick="display()">Check</button>
      <p id="demo"></p>
         function display() {
            var uri = "welcome msg.jsp?name=åmit&sub=programming";

            // first encode
            var encode = encodeURI(uri);
            var decode = decodeURI(encode);

            var result = "Encode= " + encode + "<br>" + "Decode= " + decode;
            document.getElementById("demo").innerHTML = result;
Updated on 12-Jun-2020 11:35:08