URL encoding-JS & JQuery Notes

Source: Internet
Author: User

URL Passing Special symbols

Hexadecimal value:

1. + URL + sign for space%2b

2. Spaces in the space URL can be used with the + number or code%20

3./separate directories and subdirectories%2f

4.? Separating the actual URLs and parameters%3f

5.% Specify special characters%25

6. # means bookmark%23

7. The delimiter between the parameters specified in the & URL%26

8. = value of the specified parameter in the URL%3d

Java encoding/decoding of text involves 3 pairs of functions:

Escape/unescape:

Encodes the specified string using the ISO Latin character set. All space characters, punctuation marks, special characters, and other non-ASCII characters are converted to the character encoding in the%xx format (XX equals the encoded 16-digit number of the character in the character set table). For example, the encoding for a space character is%20. The Unescape method is the opposite.

Characters that are not encoded by this method: @ */+

Encodeuri/decodeuri:

Converts the URI string into an escape format using the UTF-8 encoding format.

Characters that will not be encoded by this method:! @ # $& * () =:/;? +

encodeuricomponent/decodeuricomponent:

Converts the URI string into an escape format using the UTF-8 encoding format. Compared to encodeURI (), this method encodes more characters, such as characters. So if the string contains several parts of the URI, it cannot be encoded in this way, otherwise the URL will display an error after the/character is encoded.

Characters that will not be encoded by this method:! * ( )

Usage Recommendations :

1, for Chinese strings, if you do not want to convert the string encoding format into UTF-8 format (such as the original page and the target page charset is consistent), only need to use escape.

If your page is GB2312 or other encoding, and the page that accepts the parameter is UTF-8 encoded, it is necessary to use encodeURI or encodeuricomponent.

In addition, Encodeuri/encodeuricomponent was introduced after java1.5, and escape is available in the java1.0 version.

2, passing parameters need to use encodeuricomponent, so that the combined URL will not be # and other special characters truncated.

For example:

< language= "Java" >

Write (' <a href= ' http://passport.baidu.com/?logout&aid=7&u= '

+ encodeURIComponent ("http://cang.baidu.com/bruce42") + ' > Exit </a> ');

</>

3, the URL to jump when you can use the whole encodeURI

For example: Location.href=encodeuri ("http://cang.baidu.com/do/s?word= Baidu &ct=21");

4, JS Use the data can use escape

For example: Collection of history records.

5, Escape to the Unicode value other than 0-255 to encode the output%u**** format, in other cases escape,encodeuri,encodeuricomponent encoding results are the same.

6, the most used should be encodeuricomponent, it is the Chinese, Korean and other special characters into the utf-8 format of the URL encoding, So if you need to use encodeURIComponent to pass parameters to the background, you need the background decoding to Utf-8 support (the encoding in form is the same as the current page encoding method)

7, Escape does not encode characters have 69: *,+,-,.

URL encoding-JS & JQuery Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.