encodeURI() function in JavaScript : The encodeURI() function is used to encode the URL parameters. It only encode the special characters except: , / ? : @ & = + $ #.
Syntax of encodeURI() function :
encodeURI(uri)
uri : Required. The url which you need to encode.
Example of encodeURI() function : Here I will show you how to use encodeURI() function to encode the URL in JavaScript.
<!DOCTYPE html>
<html>
<body>
<p>To encode a URI, click the button.</p>
<button onclick="convert()">convert</button>
<p id="container"></p>
<script>
function convert() {
var url = "process.html?name=John Smith&age=25";
var result = encodeURI(url);
document.getElementById("container").innerHTML = result;
}
</script>
</body>
</html>
Output : process.html?name=John%20Smith&age=25
0 Comment(s)