Javascript examples for Global:encodeURI
The encodeURI() function encodes a URI.
This function encodes special characters, except: , / ? : @ & = + $ # which can be encoded by encodeURIComponent().
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() {/* w w w .j a va2 s . c o m*/ var uri = "https://examlle.com/my test.asp?name=st?le&car=saab"; var res = encodeURIComponent(uri); document.getElementById("demo").innerHTML = res; } </script> </body> </html>