Difference between decodeURI () and decodeURIComponent () in JS, decodeuricomponent

Source: Internet
Author: User

Difference between decodeURI () and decodeURIComponent () in JS, decodeuricomponent
Abstract:This article introduces two decoding functions: decodeURI () and decodeURIComponent (). These two functions can decrypt the cryptographic strings generated by a specific function, it can generate undecrypted strings, which is more practical. below

This article introduces two decoding functions: decodeURI () and decodeURIComponent (). These two functions can decrypt the cryptographic strings generated by a specific function, you can generate undecrypted strings, which are more practical. Let's take a look at the usage and examples of these two functions, and you will use them:

DecodeURI () Definition and usage: The decodeURI () function can decode the URI encoded by the encodeURI () function.

Syntax: decodeURI (URIstring)

Parameter description: Required for URIstring. A string containing the URI or other text to be decoded.

Returned value: a copy of URIstring. The hexadecimal escape sequence is replaced by the characters they represent.

 

DecodeURIComponent () Definition and usage: The decodeURIComponent () function can decode the URI encoded by the encodeURIComponent () function.

Syntax: decodeURIComponent (URIstring)

Parameter description: Required for URIstring. A string containing the URI component or other text to be decoded.

Returned value: a copy of URIstring. The hexadecimal escape sequence is replaced by the characters they represent.

Instance:

[Html]View plaincopy
  1. <Html>
  2. <Body>
  3. <Script type = "text/javascript">
  4. Var test1 = "http://www.wljcz.com/My first /";
  5. Var nn = encodeURI (test1 );
  6. Var now = decodeURI (test1 );
  7. Document. write (nn + "<br/> ");
  8. Document. write (now );
  9. Var test1 = "http://www.wljcz.com/My first /";
  10. Var bb = encodeURIComponent (test1 );
  11. Var nnow = decodeURIComponent (bb );
  12. Document. write (bb + "<br/> ");
  13. Document. write (nnow );
  14. </Script>
  15. </Body>
  16. </Html>


The running result is:

Http://www.wljcz.com/My%20first/
Http://www.wljcz.com/My first/

Http % 3A % 2F % 2Fwww.wljcz.com % 2FMy % 20 first % 2F
Http://www.wljcz.com/My first/

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.