Javascript examples for Global:encodeURIComponent
The encodeURIComponent() function encodes a URI component.
This function encodes special characters including: , / ? : @ & = + $ #
Parameter | Description |
---|---|
uri | Required. The URI to be encoded |
A String, representing the encoded URI
The following code shows how to Encode a URI:
<!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>