JavaScript encodeURI()
Example
Encode a URI:
let uri = "my test.asp?name=ståle&car=saab";
let encoded = encodeURI(uri);
Try it Yourself »
Description
The encodeURI()
method encodes a URI.
Note
Use the decodeURI() method to decode a URI.
Special Characters
The encodeURI()
method does not encode characters like:
, / ? : @ & = + $ * #
Use the encodeURIComponent() method instead.
See Also:
The encodeURIComponent() method to encode a URI
The decodeURIComponent() method to decode a URI
The decodeURI() method to decode a URI
Syntax
encodeURI(uri)
Parameters
Parameter | Description |
uri | Required. The URI to encode. |
Return Value
Type | Description |
A string. | The encoded URI. |
Browser Support
encodeURI()
is an ECMAScript1 (JavaScriopt 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |