Definition and Usage
The encodeURIComponent() function encodes a URI component.
This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
Tip: Use the decodeURIComponent() function to decode an encoded URI component.
Syntax
Browser Support
The encodeURIComponent() function is supported in all major browsers.
Example Encode an URI:
The output of the code above will be:
http%3A%2F%2Fgorav.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
The encodeURIComponent() function encodes a URI component.
This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
Tip: Use the decodeURIComponent() function to decode an encoded URI component.
Syntax
encodeURIComponent(uri) |
Parameter | Description |
uri | Required. The URI to be encoded |
The encodeURIComponent() function is supported in all major browsers.
Example Encode an URI:
<script type=”text/javascript”> var uri=”http://gorav.com/my test.asp?name=ståle&car=saab”; document.write(encodeURIComponent(uri)); </script> |
http%3A%2F%2Fgorav.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
No comments:
Post a Comment