JavaScript encodeURIComponent() function : The encodeURIComponent() function is used to encode the URL. It encodes the all special character including characters : , / ? : @ & = + $ #
Syntax of encodeURIComponent() function :
encodeURIComponent(url)
url : Required. This is the string parameter which need to encode.
Example of encodeURIComponent() funciton : Here is sample example to show how we can encode the URL using encodeURIComponent() function.
<!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=Sumit Vyas&age=25";
var result = encodeURIComponent(url);
document.getElementById("container").innerHTML = result;
}
</script>
</body>
</html>
Output :
process.html%3Fname%3DSumit%20Vyas%26age%3D25
0 Comment(s)