Introduction to the use of encodeURI and decodeURI methods in JavaScript

Source: Internet
Author: User

Turn from: http://www.jb51.net/article/36480.htm

encodeURI and decodeURI are used in pairs, because the browser's address bar has Chinese characters, you can have unexpected errors, so you can encodeuri to translate non-English characters into English code, decodeURI can be used to restore the characters back
I. Basic CONCEPTS
encodeURI and decodeURI are used in pairs, because the browser's address bar has Chinese characters, you can have unexpected errors, so you can encodeuri to translate non-English characters into English code, decodeURI can be used to restore the characters back. The encodeURI method does not encode the following characters: ":", "/", ";" and "?", and the encodeURIComponent method can encode these characters.
The decodeURI () method is equivalent to Java.net.URLDecoder.decode (uristring, "UTF-8");
The encodeURI () method is equivalent to Java.net.URLEncoder.encode (uristring, "UTF-8");

Second, examples

<script type= "Text/javascript" > 
var uristr = "Http://www.baidu.com?name= John &num=001"; 
var Uriec = encodeURI (URISTR); 
document.write ("encoded" + Uriec); 
var uridc = decodeURI (Uriec); 
document.write ("decoded" + URIDC); 

Http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&num=001%20zs after the encoding
Decoding of http://www.baidu.com?name= John &num=001 Zs

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.