This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

encodeURI

Summary

Encodes a text string as a valid Uniform Resource Identifier (URI)

Syntax

encodeURI( URIString )

Examples

The following code first encodes and then decodes a URI.

var uriEncode = encodeURI ("http://www.Not a URL.com");
 var uriDecode = decodeURIComponent(uriEncode);

 document.write(uriEncode);
 document.write("<br/>");
 document.write(uriDecode);

 // Output:
 // http://www.Not%20a%20URL.com
 // http://www.Not a URL.com

Remarks

The required URIString argument is a value representing an encoded URI.

The encodeURI function returns an encoded URI. If you pass the result to decodeURI , the original string is returned. The encodeURI function does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters.

See also

Other articles

Attributions

  • Microsoft Developer Network: Article