JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

13.4.4 Quirks Mode and Standards Mode

The important thing about the feature-testing technique is that it results in code that is not tied to a specific list of browser vendors or browser version numbers. It works with the set of browsers that exists today and should continue to work with future browsers, whatever feature sets they implement. Note, however, that it requires browser vendors not to define a property or method unless that property or method is fully functional. If Microsoft were to define an addEventListener() method that only partially implemented the W3C specification, it would break a lot of code that uses feature testing before calling addEventListener().

13.4.4 Quirks Mode and Standards Mode

When Microsoft released IE6, it added support for a number of standard CSS features that were not supported in IE5. In order to ensure backward compatibility with existing web content, however, it had to define two distinct rendering modes. In “standards mode” or “CSS compatibility mode,” the browser would follow CSS standards. In “quirks mode,” the browser would behave in the quirky nonstandard manner that IE4 and IE5 had. The choice of rendering modes depended on the DOCTYPE declaration at

13.4 Compatibility and Interoperability | 329

the top of the HTML file. Pages with no DOCTYPE at all and pages that declared certain permissive doctypes that were in common use during the IE5 era were rendered in quirks mode. Pages with strict doctypes (or, for forward compatibility, pages with unrecognized doctypes) were rendered in standards mode. Pages with an HTML5 doctype () are rendered in standards mode in all modern browsers.

This distinction between quirks mode and standards mode has stood the test of time. New versions of IE still implement it, other modern browsers do too, and the existence of these two modes is recognized by the HTML5 specification. The differences between quirks mode and standards mode usually matter most to people writing HTML and CSS. But client-side JavaScript code sometimes needs to know which mode a document is rendered in. To perform this kind of rendering mode feature testing, check the document.compatMode property. If it has the value “CSS1Compat,” the browser is using standards mode. If the value is “BackCompat” (or undefined if the property doesn’t exist at all), the browser is using quirks mode. All modern browsers implement the compatMode property, and the HTML5 specification standardizes it.

It is not often necessary to test compatMode. Example 15-8 illustrates one case where this test is necessary, however.

友情链接It题库(| 版权归yishouce.com所有| 友链等可联系|粤ICP备16001685号-1