JavaScript URL Several encoding methods _javascript tips

Source: Internet
Author: User

1. Escape () cannot be used directly for URL encoding, and its true function is to return a Unicode encoded value of one character. For example, "Spring Festival" return result is%u6625%u8282,escape () not "+" encoding is mainly used for man code, now has not advocated the use of.

2. encodeURI () is a function that is really used to encode URLs in JavaScript. Encodes the entire URL address, but the symbol "/?:@&=+$,#" for the special meaning is not encoded. The corresponding decoding function is decodeURI ().

3. encodeURIComponent () can encode ";/?:@&=+$,#" these special characters. The corresponding decoding function decodeuricomponent (). If you want to pass the URL with & symbol, so use encodeURIComponent ()

Summary , there is a need to pass a "+" symbol in the foreground to the background, did not think of the backstage in the automatic decoding into a space, finally found in the URL "+" corresponding to the background is a space, the space in the foreground will automatically become + to the background, so start to "+" to encode, If you determine that there may be a "+" in the argument, the value is first encodeuricomponent () to encode it, to the background value will become "+".

The above JavaScript URL several coding methods are small parts to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

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.