Javascript-Uri encoding and decoding method

Source: Internet
Author: User

After a long vacation, I had some trouble returning to the company. I was interrupted in my previous study plan and work plan. I didn't even know what to do when I came back. So I ran to my colleague's blog and came back to read my previous notes. Now I will continue to learn JavaScript.

A valid uri (Uniform Resource Identifier) cannot contain certain characters, such as spaces. Therefore, the URI must be encoded by: encodeuri () and encodeuricomponent (),

The encoding decoding methods include decodeuri () and decodeuricomponent ().

Encodeuri () encoding codeOnlyDecodeuri () Solution

Encodeuricomponent () CodeOnlyDecodeuricomponent () solution,

Encodeuri (): used to encode the complete URI. It does not encode special characters in the URI, such as colons, front slashes, question marks, and pound signs.

 
 var str0=encodeURI("http://www.cnblogs.com/ 2012/ 71.html");
Results: http://www.cnblogs.com/%202012/%2071.html
Only spaces are encoded.

Encodeuricomponent (): used to encode a part of a URI. It encodes all non-standard characters in the URI.

var str1=encodeURIComponent("http://www.cnblogs.com/ 2012/ 71.html");
Result: http%3a%2f%2fwww.cnblogs.com%2f%202012%2f%2071.html
Encode all non-standard characters
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.