JavaScript code involves three functions: Escape, encodeuri, and encodeuricomponent. The corresponding three decoding functions are: Unescape, decodeuri, and decodeuricomponent.
And Asp.net'sServer. urldecodeDecoding.
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.
[Edit huoho. com]
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-(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
The escape (STR) method, which is used to escape any characters that cannot be correctly sent in plain text. For example, the space in the phone number is converted to % 20, so that these characters can be passed in the URL.
therefore, for Chinese strings, if you do not want to convert the string encoding format to the UTF-8 format (for example, when the charset of the original page and the target page is consistent), you only need to use escape. If your page is gb2312 or another code, and the page that accepts the parameter is UTF-8 code, use encodeuri or encodeuricomponent.
note : the escape method cannot be used to encode the Uniform Resource Identifier (URI. Use the encodeuri and encodeuricomponent methods for encoding.