JS in decodeURI () and decodeURIComponent ()

Source: Internet
Author: User

Summary:This article is about two decoding functions, they are the decodeURI () and decodeURIComponent () functions, these two functions can be generated by a particular function of the cryptographic string decryption operation, it can be produced as an unencrypted string, more practical, the following

This article is about two decoding functions, they are the decodeURI () and the decodeURIComponent () function, these two functions can be generated by a particular function of the cryptographic string decryption operation, it can be born into an unencrypted string, more practical, Let's take a look at the usage and examples of these two functions, and you'll use:

decodeURI () Definition and usage: the decodeURI () function decodes a URI encoded by the encodeURI () function.

Syntax: decodeURI (uristring)

Parameter description: uristring required. A string that contains the URI to decode or other text to decode.

Return value: A copy of uristring, where the hexadecimal escape sequence is replaced by the character they represent.

decodeURIComponent () Definition and usage: the decodeURIComponent () function decodes the URI encoded by the encodeURIComponent () function.

Syntax: decodeURIComponent (uristring)

Parameter description: uristring required. A string that contains the encoding URI component or other text to decode.

Return value: A copy of uristring, where the hexadecimal escape sequence is replaced by the character they represent.

Instance:

  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 result of this operation is:

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

http%3a%2f%2fwww.wljcz.com%2fmy%20first%2f
Http://www.wljcz.com/My first/

Reprint: http://blog.csdn.net/luqin1988/article/details/7878053

JS in decodeURI () and decodeURIComponent ()

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.