The encodeURI() function is used to encode a URI. This function encodes all special characters, except these < , / ? : @ & = + $ #>.
Example :
var uri="http://www.freetimelearning.com/this is a educational website";
var encodedURI = encodeURI(uri);
console.log(encodedURI);
Output :
http://www.freetimelearning.com/this%20is%20a%20educational%20website