JavaScript encodeURI() Function
The encodeURI() function encodes a complete URL, leaving characters with special meaning in URLs, such as / ? & and #, intact.
Description
The encodeURI() function encodes a whole URL. Unlike encodeURIComponent(), it leaves characters that structure a URL, such as :, /, ?, &, = and #, unchanged, and only encodes characters like spaces and non-ASCII letters.
Because it leaves &, = and ? alone, using it on a single value meant for a query string is a bug: a value containing & would split into two parameters. Use encodeURIComponent() for values.
In modern code, the URL object is usually a better way to build and clean up URLs: new URL(path, base) encodes as needed, and its searchParams property handles query values safely.
Syntax
encodeURI(uri)Parameters
- uriA complete URL.
Return Value
The URL with characters that aren't allowed in URLs percent-encoded.
Example
Browser Support
The following information will show you the current browser support for the encodeURI() function. Hover over a browser icon to see the version that first introduced support for this function.
Desktop





Tablets & Mobile





