Latest web development tutorials

JavaScript encodeURI () function

Function Reference Manual JavaScript Global Functions

Definition and Usage

encodeURI () function to encode the string as a URI.

The following ASCII punctuation has special meaning in the URI, encodeURI () function will not be escaped:, /?: @ & = + $ # (You can use encodeURIComponent () method, respectively special meaning ASCII punctuation encoded.).

Tip: Use decodeURI () method can be encoded URI (Universal Resource Identifier: UniformResourceIdentifier, referred to as the "URI").

grammar

encodeURI(uri)

参数 描述
uri 必需。一个字符串,含有 URI 或其他要编码的文本。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support encodeURI () function.


Examples

Example

Use encodeURI () to encode the URI:

<script>

var uri="my test.asp?name=stale&car=saab";
document.write(encodeURI(uri)+ "<br>");

</script>

Examples of the above output:

my%20test.php?name=st%C3%A5le&car=saab

try it"


Function Reference Manual JavaScript Global Functions