Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

encodeURI Function (JavaScript)

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

encodeURI(URIString)

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.

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

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft