Search w3schools.com:

SHARE THIS PAGE

JavaScript encodeURIComponent() Function

Function Reference JavaScript Global 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 an encoded URI component.

Syntax

encodeURIComponent(uri)

Parameter Description
uri Required. The URI to be encoded


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The encodeURIComponent() function is supported in all major browsers.


Example

Example

Encode an URI:

<script>

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 Global Functions

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]