24.72. encodeURI( ): escape characters in a URIECMAScript v324.72.1. SynopsisencodeURI(uri) 24.72.1.1. Arguments
24.72.1.2. ReturnsA copy of uri, with certain characters replaced by hexadecimal escape sequences. 24.72.1.3. Throws
24.72.2. DescriptionencodeURI( ) is a global function that returns an encoded copy of its uri argument. ASCII letters and digits are not encoded, nor are the following ASCII punctuation characters: - _ . ! ~ * ' ( ) Because encodeURI( ) is intended to encode complete URIs, the following ASCII punctuation characters, which have special meaning in URIs, are not escaped either: ; / ? : @ & = + $ , # Any other characters in uri are replaced by converting each character to its UTF-8 encoding and then encoding each of the resulting one, two, or three bytes with a hexadecimal escape sequence of the form %xx. In this encoding scheme, ASCII characters are replaced with a single %xx escape, characters with encodings between \u0080 and \u07ff are replaced with two escape sequences, and all other 16-bit Unicode characters are replaced with three escape sequences. If you use this method to encode a URI, you should be certain that none of the components of the URI (such as the query string) contain URI separator characters such as ? and #. If the components have to contain these characters, you should encode each component separately with encodeURIComponent( ). Use decodeURI( ) to reverse the encoding applied by this method. Prior to ECMAScript v3, you can use escape( ) and unescape( ) methods (which are now deprecated) to perform a similar kind of encoding and decoding. 24.72.3. Example// Returns http://www.isp.com/app.cgi?arg1=1&arg2=hello%20world encodeURI("http://www.isp.com/app.cgi?arg1=1&arg2=hello world"); encodeURI("\u00a9"); // The copyright character encodes to %C2%A9 24.72.4. See AlsodecodeURI( ), decodeURIComponent( ), encodeURIComponent( ), escape( ), unescape( ) |