0

How to encode URL in JavaScript

JavaScript
var urlVar = encodeURI("This text can be passed on a url now");
JavaScript
var uri = "my test.asp?name=ståle&car=saab";
var res = encodeURI(uri); 

console.log(res); // "my%20test.asp?name=st%C3%A5le&car=saab"
RUN
JavaScript
var encodeURI = encodeURIComponent("&");

console.log(encodeURI); // "%26"
RUN
add comment
Suggest a different solution or add another example