2 Ways To Decode URLs In Javascript

Hello friend, hope you are doing well. In the previous article “2 Ways To Encode URLs Using Javascript“, I explained the ways to encode URLs. Now in this article, I will explain the ways to decode URLs in Javascript. So let’s start it.

Ways To Decode URLs

  1. Using decodeURI()
  2. Using decodeURLComponent()

1. Using decodeURI()

This function is used to decode an URL. Check the below example.

var url = 'https://www.demoDomain.com?x=шеллы&y=шеллы';
var encodedUrl = encodeURI(url);
console.log("Encoded URL :: " + encodedUrl);
var decodedUrl = decodeURI(encodedUrl);
console.log("Decoded URL :: " + decodedUrl);

2. Using decodedURIComponent()

This method is also used to decode URLs. Check the below example. In the below example. In the below example, we will encode the URL using the encodeURIComponent() method, then we will decode it using the decodeURIComponent() method.

var url = 'https://www.demoDomain.com?x=шеллы&y=шеллы';
var encodedUrl = encodeURIComponent(url);
console.log("Encoded URL :: " + encodedUrl);
var decodedUrl = decodeURIComponent(encodedUrl);
console.log("Decoded URL :: " + decodedUrl);

 

 

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories