JavaScript encodeURI() function

Definition and usage

encodeURI() Function used to encode URI.

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

Tip:Use decodeURI() Function to decode already encoded URI.

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: String, representing the encoded URI.

Browser support

Funktion Chrome Edge Firefox Safari Opera
encodeURI() Unterstützung Unterstützung Unterstützung Unterstützung Unterstützung