Browser encoding Issues

Source: Internet
Author: User

browser in parsing HTML, according to a certain format and encoding to parse, in order not to disturb the HTML structure, there is HTML encoding (such as:< correspondence &lt;), in order not to disturb the syntax of JS, there is JS code (such as: ' corresponding \ '), in order to parse the URL normally, There are URL encodings (such as:& corresponding to%26). summed up in three categories, but there are different forms of coding.

1.1.1 HTML Encoding

The most common forms of HTML encoding are three: alias form, 16 binary form, 10 binary form, such as:<> "' encoded in these three ways, respectively, as follows:

Alias form:&lt;&gt;&quot;&apos;

16 binary form:& #x3c;& #x22;& #x27 of #x3e;&;

10 binary form:& #60;& #34;& #39 of #62;&;

There are several ways that HTML encoding can be mixed, and the browser can parse it normally.

1.1.2 JS Code

The most common types of JS encoding are four: Slash escape form, 16 binary form, Unicode encoding form. <> "' is encoded in these ways as follows:

Slash escape form: \<\>\ "\"

16 binary form: \x3c\x3e\x22\x27

Unicode encoding form: \u003c\u003e\u0022\u0027

These methods can also be mixed up. It should be noted that the general backslash escape form does not escape letters or numbers, because there may be confusion, such as: \x\3\c does not parse into x3c as it is imagined, but rather reports grammatical errors.

1.1.3 URL Encoding

URL coding estimates are very familiar to everyone, the code is in the form of%xx, such as the same <> "' by URL encoding%3c%3e%22%27.

The URL encoding needs to be noted that only the parameter values in the URL are encoded, such as: http://xxx.com?p1=%3C%3E%22%27, the browser can correctly identify the URL and parameters.


If the entire URL is encoded, the browser is unrecognized and will be recognized as relative road strength, see.

1.2 Coded position

HTML pages We can encode in the specified encoding format, but must conform to the browser's decoding rules and order, otherwise the browser will not be recognized.

1.2.1 HTML Encoding applicable location

HTML encoding applies to the value of the property, the contents of the tag, see the following example:

After the browser resolves such as:


can see:

1, the tag using HTML encoding, is parsed out, and does not affect the structure of the DOM.

2, the attribute value is parsed out using HTML encoding, and also in the URL, JS event, CSS.

3. The attribute name is encoded using HTML and is not parsed.

However, in the <script> tag JS content and <style> CSS content, the browser will not use HTML encoding decoding:


1.2.2 JS Coding Applicable location

JS encoding is only applicable to JS code, including <script> and JS events:


1.2.3 URL Encoding Usage location

URL encoding applies only to property values that are URLs, and URL encoding is only available for the parameters in the URL. such as the href attribute of the:<a> tag, the src attribute of <iframe>, etc.

1.3 Decoding sequence

Since each coding has its own location, and this position will certainly overlap, so the browser decoding must have a certain order. The general decoding order is: HTML decoding > URL decoding > JS decoding, see a simple example:


The href attribute value of,<a> in this example is a JS code, so there are three kinds of decoding: HTML decoding, URL decoding, JS decoding. In the order described above, the browser first HTML decoding, HTML decoding after the following:


Then do the URL decoding, after decoding the following:


Finally do JS decoding, so the content of the final popup window should be "XXX." The content of the actual pop-up window is the same.



Browser Encoding issues

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.