Non-blank characters before the DTD may invalidate the DTD in some cases.

Source: Internet
Author: User

Http://w3help.org/zh-cn/causes/HG8001

Standard Reference

As mentioned in the HTML 4.01 standard, a blank character is allowed before or after the DTD. The "blank character" mentioned here includesSpace Character,Line Break,TabAndNote.

For details about the structure of HTML documents, refer to the content in HTML 4.01 standard 7.1 Introduction to the structure of an HTML document.

Problem description

If you add comments or other content before a DTD, The DTD cannot be recognized in some browsers.

Impact

This problem will cause the same page to work in some browsers in standard mode (S) and other browsers to work in hybrid mode (Q, as a result, the performance of the page varies greatly in various browsers, such as layout disorder, overlapping content, and unavailability of functions.

Affected browsers

IE6
Any non-blank characters before the DTD will make the browser ignore the DTD, including comments and XML declarations.

IE7 IE8
Any non-blank characters before the DTD will cause the browser to ignore the DTD, including comments, but not XML declarations.

Firefox
Any character that contains "<" before the DTD will make the browser ignore the DTD, but does not include the XML declaration.

Chrome Safari Opera
Any non-blank characters before the DTD will make the browser ignore the DTD, but do not include the XML declaration.

Problem Analysis

If other characters appear before the DTD of an HTML document, the processing conditions in different browsers are inconsistent.

For specific differences, see the following table:

If
Can the browser recognize this DTD?

 

[Note]
1. HTML comments, such as <! -- Comment -->.
2. Similar to <? Xml version = "1.0" encoding = "UTF-8"?> .
3. It is not a space character, line break, or Tab character, nor any other string declared by comments or XML, but cannot contain the "<" character.
4. It is not a space character, line break, or Tab character, or any other string declared by comments or XML, including the "<" character.

Through the comparison above, we can see that to ensure that the DTD can be properly recognized in all browsers, it can only appear beforeSpace Character,Line BreakAndTab.

Solution

When declaring a DTD, make sure that the DTD has no other characters.Space Character,Line BreakAndTab.

For example, place the DTD In the first line of the HTML document.

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.