JavaScript encodeURI() function

Definition and usage

encodeURI() The function is used to encode URIs.

This function encodes special characters except: , / ? : @ & = + $ # (use encodeURIComponent() to encode these characters).

Tip:Use decodeURI() The function decodes a URI that has already been encoded.

Example

Encode URI:

var uri = "my test.asp?name=ståle&car=saab";
var res = encodeURI(uri);

Try it yourself

Syntax

encodeURI(uri)

Parameter value

Parameter Description
uri Required. The URI to be encoded.

Technical details

Return value: A string representing the encoded URI.

Browser support

Function Chrome Edge Firefox Safari Opera
encodeURI() Support Support Support Support Support