Availability
JavaScript 1.5; JScript 5.5; ECMAScript v3
Synopsis
encodeURI(uri)Arguments
uri
A string that contains the URI or other text to be encoded.
Returns
A copy of uri, with certain characters
replaced by hexadecimal escape sequences.
Throws
URIError
Indicates that uri contains malformed
Unicode surrogate pairs and cannot be encoded.
Description
encodeURI( ) 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 the 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 may
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.
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
See Also
decodeURI( ), decodeURIComponent( ), encodeURIComponent( ),
escape( ), unescape( )
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.