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.
3 out of 6 rated this helpful - Rate this topic

encodeURIComponent Function (JavaScript)

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

encodeURIComponent(encodedURIString)

The required encodedURIString argument is a value representing an encoded URI component.

The encodeURIComponent function returns an encoded URI. If you pass the result to decodeURIComponent, the original string is returned. Because the encodeURIComponent function encodes all characters, be careful if the string represents a path such as /folder1/folder2/default.html. The slash characters will be encoded and will not be valid if sent as a request to a web server. Use the encodeURI function if the string contains more than a single URI component.

The following code first encodes a URI component and then decodes it.

var uriEncode = encodeURIComponent ("www.Not a URL.com");
var uriDecode = decodeURIComponent(uriEncode);

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

// Output:
// www.Not%20a%20URL.com
// 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.