Javascript URL encoding conversion, escape () encodeuri () encodeuricomponent (), Asp.netUrldecodeDecoding.
This article introduces three functions of URL encoding: escape (), encodeuri (), encodeuricomponent ()
Escape () method:
The specified string is encoded using the ISO Latin character set. All space characters, punctuation marks, special characters, and other non-ASCII characters will be converted into character encoding in % XX format (XX equals to the hexadecimal encoding of this character in the character set table number ). For example, the space character is encoded as % 20. The Unescape method is the opposite. Characters not encoded by this method: @ */+
Encodeuri () method:
Convert a URI string to an escape string in UTF-8 encoding format. Characters not encoded by this method :! @ # $ & * () = :/;? +'
Encodeuricomponent () method:
Convert a URI string to an escape string in UTF-8 encoding format. Compared with encodeuri (), this method will encode more characters, such. Therefore, if the string contains several parts of the URI, this method cannot be used for encoding. Otherwise, the URL will display an error after the/character is encoded. Characters not encoded by this method :! *()
Therefore, for a Chinese string, 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.
In addition, Encodeuri/encodeuricomponent is introduced after javascript1.5, and escape is available in javascript1.0.