The encodeURI () function encodes a string as a URI.
Grammar
encodeURI (uristring)
| Parameters |
Description |
| Uristring |
Necessary. A string that contains the URI or other text to encode. |
return value
A copy of the uristring, where some of the characters will be replaced by a hexadecimal escape sequence.
Description
The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ().
The purpose of this method is to fully encode the URI, so the encodeURI () function is not escaped for the following ASCII punctuation mark with a special meaning in the URI:;/?:@&=+$,#
Hints and Notes
Tip: If the URI component contains delimiters, such as? and #, each component should be encoded using the encodeURIComponent () method.
The decoding of this method is decodeURI ()
Ii. Definition and usage
The escape () function encodes the string so that it can be read on all computers.
Grammar
Escape (String)
| Parameters |
Description |
| String |
Necessary. The string to be escaped or encoded. |
return value
A copy of the encoded string. Some of these characters are replaced with 16-binary escape sequences.
Description
The method does not encode ASCII letters and numbers, nor does it encode the following ASCII punctuation marks:-_. ! ~ * ' (). All other characters will be replaced by escape sequences.
Hints and Notes
Tip: You can use Unescape () to decode an escape () encoded string.
Note: ECMAScript v3 against using this method, the app uses decodeURI () and decodeuricomponent () to replace it.
C. JavaScript encodeuricomponent () function definition and usage
The encodeURIComponent () function encodes a string as a URI component.
Grammar
encodeURIComponent (uristring)
| Parameters |
Description |
| Uristring |
Necessary. A string that contains the URI component or other text to encode. |
return value
A copy of the uristring, where some of the characters will be replaced by a hexadecimal escape sequence.
Description
The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ().
Other characters (such as:;/?:@&=+$,# These punctuation marks used to separate the URI component) are replaced by one or more hexadecimal escape sequences.
Hints and Notes
Tip: Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string). Therefore, the encodeURIComponent () function escapes punctuation marks that are used to separate the various portions of the URI.
This method decodes the way decodeuricomponent
JS encoding decoding