JavaScript encodeURI()Function

函数参考手册JavaScript Global Functions

Definition and Usage

The encodeURI() function encodes a string as a URI.

The encodeURI() function does not escape the following ASCII punctuation marks with special meaning in URIs: , / ? : @ & = + $ # (you can useencodeURIComponent()method to encode the ASCII punctuation marks with special meaning separately.)

Tip:UsedecodeURI()The method can decode a URI (Uniform Resource Identifier, abbreviated "URI").

Syntax

encodeURI(uri)

Parameter Description
uri Required. A string containing a URI or other text to encode.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the encodeURI() function.


Example

Example

Encode a URI using encodeURI():

var uri="my test.php?name=ståle&car=saab"; document.write(encodeURI(uri)+ "<br>");

The output of the above example is:

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

Try it »


函数参考手册JavaScript Global Functions Other Extensions