encodeURIComponent() global function JS Home  <<  JS Reference  <<  encodeURIComponent()

Global function URI encoding.

Description

Encodes the special characters of a passed uri including the following:


 ; , / ? : @ & = + $ #
  

Syntax

Signature Description
encodeURIComponent(uri)Encodes the special characters of a passed uri.

Parameters

Parameter Description
uriThe uri to encode.

Below is an example of using the encodeURIComponent() function.


// Encode a uri 
var uri="a spurious name.com?firstname=barney&surname=magrew";

alert(encodeURIComponent(uri));  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 9 - Any Other Business