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> '); </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
Reply: What is the difference between encodeuri and escape in JavaScript?
Escape () method:
All spaces, punctuation marks, accent characters, and any other non-ASCII characters are encoded in the form of "% xx", which is represented by hexadecimal numbers.
Escape and Unescape encoding and decoding functions. Escape returns a hexadecimal encoded ISO Latin character set. Unescape function to convert hexadecimal encoded with special values to ASCII strings.
Example:
Escape ('! @ # $ % ^ & * () {} [] = :/;? + \'"'):
Result: % 21 @ % 23% 24% 25% 5E % 26 * % 28% 7b % 7D % 5B % 5d % 3d % 3A/% 3B % 3f + % 29% 22
encodeuri () method
the encodeuri method returns an encoded Uri. therefore, if you use the decodeuri method for the result, the original string will return. the encodeuri method is not encoded with the following characters :":","/",";","? ". However, encodeuricomponent can be used to encode these characters.
encodes, an Uniform Resource Identifier (URI) replaces some characters one by one and describes the characteristics of UTF-8 encoding.
example:
encodeuri ('! @ # $ % ^ & * () {} [] = :/;? + \ '"'):
result :! @ # $ % 25% 5E & * () % 7b % 7D % 5B % 5d = :/;? + '% 22
Encodeuricomponent () method:
The encodeuricomponent method returns an encoded Uri. therefore, if you decodeuricomponent, the original string will return. because all text encodesencodeuricomponent methods are encoded, be careful if there are paths and other strings such as: "/folder1/folder2/default. html ". after encryption, the request will not expire if it is used as a network server. use this method to encodeuri a string consisting of more than one Uri.
Encodes, an Uniform Resource Identifier (URI) that replaces some characters one by one and describes the characteristics of UTF-8 encoding.
Example: the simplest method is to encrypt these characters and generateCode.
Encodeuricomponent ('! @ # $ % ^ & * () {} [] = :/;? + \'"'):
Result! % 40% 23% 24% 25% 5E % 26 * () % 7b % 7D % 5B % 5d % 3d % 3A % 2f % 3B % 3f % 2B '% 22
--------------------------------------------------------------------------------
Reply: What is the difference between encodeuri and escape in JavaScript?
When is the applicable method?
The escape () method is not encrypted + is parsed as spaces on the server side and spaces in the form forms area. based on this reduction method, you should try to avoid using this method. If you select either method, you 'd better use encodeuricomponent () frequently ().
Escape () is not encrypted: @ */+
Using encodeuri () is slightly more specialized than escape (), which is for Uris encoding. it is the opposite of querystring and belongs to a part of the URL. this method is used when you need to convert a string to the Uris resource ID and some characters need to be kept in a non-encode state. remember, this character is not encoded, because it is included in Uris.
Encodeuri () is not encrypted :! @ # $ & * () = :/;? +'
Finally, the encodeuricomponent () method is used in most cases. When you need to encode a separate Uris part, this method can encrypt some special characters for Uris, therefore, most parts can be included in the table. remember, 'the character is included in Uris, so this method will not encode it.
Encodeuricomponent () is not encrypted :! *()'
Http://shijian0306.javaeye.com/blog/241264