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:Please use decodeURI() Function to decode the URI that has 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 supports

函数 Chrome Edge Firefox Safari Opera
encodeURI() 支持 支持 支持 支持 支持