Javascript - Global encodeURI() Function

The encodeURI() function is used to encode a URI.

Description

The encodeURI() function is used to encode a URI.

This function encodes special characters, except: , / ? : @ & = + $ #

You can use encodeURIComponent() to encode these characters.

Syntax

encodeURI(uri)

Parameter Values

Parameter Require Description
uri Required. The URI to be encoded

Return

A String, representing the encoded URI

Example

Encode a URI:

Demo

var uri = "my test.asp?name=json&lang=java";
var res = encodeURI(uri);
console.log(res);

Result