Global encodeURIComponent() Function - Javascript Global

Javascript examples for Global:encodeURIComponent

Description

The encodeURIComponent() function encodes a URI component.

This function encodes special characters including: , / ? : @ & = + $ #

Parameter Values

Parameter Description
uri Required. The URI to be encoded

Return Value:

A String, representing the encoded URI

The following code shows how to Encode a URI:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//ww  w.  ja va2  s . co  m
    var uri = "https://example.com/my test.asp?name=st?le&car=saab";
    var res = encodeURIComponent(uri);
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials