Definition and Usage The encodeURI() function encodes a string as a component of a URI. Syntax encodeURIComponent(URIstring) ...
Definition and Usage
The encodeURI() function encodes a string as a component of a URI.Syntax
encodeURIComponent(URIstring) |
Parameter | Description |
---|---|
URIstring | Required. The URI to be encoded |
Tips and Notes
Tip: Use the decodeURIComponent() function to decode URIs encoded with encodeURIComponent().Example
In this example we use encodeURIComponent() to encode URIs:<script type="text/javascript"> document.write(encodeURIComponent("http://www.google.com")); document.write("<br />"); document.write(encodeURIComponent("http://www.google.com/p 1/")); document.write("<br />"); document.write(encodeURIComponent(",/?:@&=+$#")); </script> |
The output of the code above will be:
http%3A%2F%2Fwww.google.com http%3A%2F%2Fwww.google.com%2Fp%201%2F %2C%2F%3F%3A%40%26%3D%2B%24%23 |