JavaScript code involves three functions: escape, encodeURI, and encodeURIComponent. The corresponding three decoding functions are: unescape, decodeURI, and decodeURIComponent.
1. encodeURIComponent is required when passing parameters so that the combined url will not be truncated by special characters such.
Example: <script language = "javascript"> document. write ('<a href = "http://passport.baidu.com /? Logout & aid = 7 & u = '+ encodeURIComponent ("http://cang.baidu.com/bruce42") +' "> exit </a & gt; '); </script>
2. encodeURI can be used for url redirection.
Example: Location. href = "/encodeURI" ("http://cang.baidu.com/do/s? Word = Baidu & ct = 21 ");
3. You can use escape when js uses data.
For example, search for the history record in the bucket.
4. When encoding unicode values other than 0-, escape outputs % u *** format. In other cases, escape, encodeURI, and encodeURIComponent have the same encoding result.
The most commonly used format is encodeURIComponent, which converts special characters such as Chinese and Korean into UTF-8 url encoding, therefore, if you want to use encodeURIComponent to transmit parameters to the backend, you must use backend decoding to support UTF-8 (the encoding method in form is the same as that on the current page)
Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, a-z, A-Z
EncodeURI is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, a-z, A-Z
EncodeURIComponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, a-z, A-Z
Author: ERDP Technical Architecture"