From http://www.w3schools.com (Copyright Refsnes Data)

JavaScript encodeURIComponent() Function


Function Reference JavaScript Functions

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 URIs encoded with encodeURIComponent().

Syntax

encodeURIComponent(uri)

Parameter Description
uri Required. The URI to be encoded


Example

Example

Encode an URI:

<script type="text/javascript">

var uri="http://w3schools.com/my test.asp?name=ståle&car=saab";
document.write(encodeURIComponent(uri));

</script>

The output of the code above will be:

http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab

Try it yourself »


Function Reference JavaScript Functions

From http://www.w3schools.com (Copyright Refsnes Data)