May 7, 2000 - ASCII-URI Conversions | WebReference

May 7, 2000 - ASCII-URI Conversions

Yehuda Shiran May 7, 2000
ASCII-URI Conversions
Tips: May 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

The URI (Universal Resource Index) is a standard format for specifying resources over the Internet. The principle behind this standard is that all its member characters are alphanumeric. All non-alphanumeric characters are replaced by a string in the form of "%xy" where xy being the ASCII encoding of the non-alphanumeric character. The target set of characters belong to to the ISO Latin-1 character set. The ISO Latin-1 (8859-1) is the standard set of characters used over the Internet. Only this standard is guaranteed to be supported on a Web site.

Internet Explorer 5.5 introduced four new methods to encode strings to URIs as well as to decode URIs to strings. The first method, encodeURI(string), encodes a string as a full URI. Let's take an example. The following line:

encodeURI("My phone # is 123-456-7890")); 

should generate the following string:


The other three methods are encodeURIComponent(), decodeURI(), and decodeURIComponent(). Read all about them in Column 59, IE 5.5: Formatting, URIs, and Stack Operations.