The URI component encoding is yield by the function called encodeURIComponent(). This function encodes special characters like this: , / ? : @ & = + $ #. We can use the decodeURIComponent() function to decode an encoded URI component.
Syntax:
encodeURIComponent(uri)
It returns a string representing the encoded URI.
Example:
<!DOCTYPE html>
<html>
<body>
<button onclick="encodeFunction()">click here to see encoding</button>
<p id="view"></p>
<script>
function encodeFunction() {
var uri = "http://w3schools.com/my test.asp?name=stle&car=saab";
var res = encodeURIComponent(uri);
document.getElementById("view").innerHTML = res;
}
</script>
</body>
</html>
0 Comment(s)