Home > Web Front-end > JS Tutorial > body text

javascript three encoding and decoding methods_javascript skills

WBOY
Release: 2016-05-16 18:35:37
Original
1868 people have browsed it

1. You need to use encodeURIComponent when passing parameters, so that the combined URL will not be truncated by special characters such as #.

For example:


2. You can use encodeURI as a whole when performing url jump

For example: Location.href=encodeURI("http://cang.baidu .com/do/s?word=Baidu&ct=21");

3. You can use escape when using data in js[Huoho.Com editor]

For example: history record in collection .

4. When escape encodes unicode values ​​other than 0-255, it outputs the %u**** format. In other cases, the encoding results of escape, encodeURI, and encodeURIComponent are the same.

The most commonly used one should be encodeURIComponent, which converts Chinese, Korean and other special characters into url encoding in utf-8 format. Therefore, if you need to use encodeURIComponent to pass parameters to the background, you need background decoding to support utf-8. (The encoding method in the form is the same as the encoding method of the current page)

There are 69 characters that are not encoded by escape: *, , -, ., /, @, _, 0-9, a-z, A-Z

encodeURI has 82 non-encoded characters: !, #, $, &, ', (,), *, ,,, -,.,/,:,;,=,?,@,_,~, 0-9, a-z, A-Z

encodeURIComponent has 71 unencoded characters: !, ', (,), *, -, ., _, ~, 0-9, a-z, A-Z

================================================== ========

unescape method

Returns the decoded string from a String object encoded with the escape method.

function unescape(charString : String) : String


Parameters

charString

Required. The String object or text to decode.

Remarks

The unescape method returns a string value containing the contents of charstring. All characters encoded in %xx hexadecimal form are replaced by equivalent characters in the ASCII character set. Characters encoded in the format %uxxxx (Unicode characters) are replaced with Unicode characters with hexadecimal encoding xxxx. Note The unescape method should not be used to decode Uniform Resource Identifiers (URIs). Please use the decodeURI and decodeURIComponent methods instead.

decodeURI method

Returns an unencoded form of an encoded Uniform Resource Identifier (URI).

function decodeURI(URIstring : String) : String

Parameters

URIstring

Required. A string representing the encoded URI.

Remarks

Use the decodeURI method instead of the obsolete unescape method.

The decodeURI method returns a string value.

If the URIString is invalid, a URIError will occur.

decodeURIComponent method

Returns the unencoded form of an encoded component of a Uniform Resource Identifier (URI).

function decodeURIComponent(encodedURIString : String) : String

The required encodedURIString parameter is a value representing the encoded URI component.

Remarks
URIComponent is part of a complete URI

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!