What is encodeURI() function and explain its usage?

Solution

The encodeURI() function is used to encode a URI. This function encodes special characters, except: , / ? : @ & = + $ #

For example:-

var uri="http://www.modernpathshala.com/how to make a website using javaScript";
var encodedURI = encodeURI(uri);
console.log(encodedURI);

Output

http://www.modernpathshala.com/how%20to%20make%20a%20website%20using%20javaScript

You can clearly see that space between words in uri variable is encoded as %20 in encodedURI variable. 

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media