Introduction to the use of encodeURI and decodeURI methods in JavaScript

Source: Internet
Author: User

encodeURI and decodeURI are used in pairs, because the address bar of the browser has Chinese characters, which can cause unexpected errors.

So you can encodeuri non-English characters into English code, decodeURI can be used to restore the characters back

first, the basic concept
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 non-English characters into English encoding,

decodeURI can be used to restore 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");

Ii. examples

var uristr = "http://www.baidu.com?name= Zhang San &num=001 zs"var uriec = encodeURI (uristr ); document.write ("encoded" +var uridc = decodeURI (Uriec); document.write ("decoded" +

Http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&num=001%20zs after encoding
Decoded http://www.baidu.com?name= Zhang San &num=001 zs

Introduction to the use of encodeURI and decodeURI methods in JavaScript

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.