JavaScript encodeURI() Function
JavaScript Global Functions
Definition and Usage
The encodeURI() function encodes a string as a URI.
The encodeURI() function does not escape the following ASCII punctuation that has special meaning in a URI: , / ? : @ & = + $ # (you can use encodeURIComponent() the method to encode the ASCII punctuation with special meaning separately.)
**Tip:** Use decodeURI() The method can decode a URI (Uniform Resource Identifier, abbreviated as "URI").
Syntax
encodeURI(uri)
| Parameters | Description |
|---|---|
| uri | Required. A string containing a URI or other text to be encoded. |
Browser support





All major browsers support the encodeURI() function.
Example
Example
Use encodeURI() to encode a URI:
var
uri
=
"
my test.php?name=ståle&car=saab
"
;
document
.
write
(
encodeURI
(
uri
)
"
"
)
;
The example above produces the following output:
my%20test.php?name=st%C3%A5le&car=saab
Try it »
JavaScript Global Functions