Latest web development tutorials
 

JavaScript encodeURIComponent() Function

< JavaScript Global Functions

Example

Encode a URI:

var uri = "http://w3ii.com/my test.asp?name=stale&car=saab";
var res = encodeURIComponent(uri);

The result of res will be:

http%3A%2F%2Fw3ii.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
Try it Yourself »

Definition and Usage

The encodeURIComponent() function encodes a URI component.

This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #

Tip: Use the decodeURIComponent() function to decode an encoded URI component.


Browser Support

Function
encodeURIComponent() Yes Yes Yes Yes Yes

Syntax

encodeURIComponent(uri)

Parameter Values

Parameter Description
uri Required. The URI to be encoded

Technical Details

Return Value: A String, representing the encoded URI

< JavaScript Global Functions