How to encode and decode a URL in JavaScript?

devquora
devquora

Posted On: Feb 22, 2018

 

encodeURI() function is used to encode an URL in Javascript.It takes a url string as parameter and return encoded string. Note: encodeURI() did not encode characters like / ? : @ & = + $ #, if you have to encode these characters too please use encodeURIComponent(). Usage:

var uri = "my profile.php?name=sammer&occupation=pāntiNG";
var encoded_uri = encodeURI(uri);

decodeURI() function is used to decode an URL in Javascript.It takes a encoded url string as parameter and return decoded string. Usage:

var uri = "my profile.php?name=sammer&occupation=pāntiNG";
var encoded_uri = encodeURI(uri);
decodeURI(encoded_uri);

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    JavaScript Interview Questions

    Explain what is Javascript?

    Javascript Javascript is an object-oriented computer programming language commonly used to create interactive effects wi..