Home >Web Front-end >JS Tutorial >Attributes in js: document.compatMode

Attributes in js: document.compatMode

零下一度
零下一度Original
2017-07-26 18:06:141384browse

When I was checking information today, I accidentally discovered an attribute that I had not noticed before: document.compatMode

After some information inquiry, I learned the following information:

We all know IE There are two box models. When !DOCTYPE is not declared, it is Quirks Mode. When !DOCTYPE is declared, it is consistent with other standard browsers and is Standards Mode.

document.compatMode Yes Two attribute values:

BackCompat ----- indicates that the standard specification mode is turned off, that is, it is currently in mixed mode (Quirks Mode). At this time, the width of the browser client area is document.body.clientWidth

CSS1Compat ---- Indicates that the standard specification mode is turned on, that is, it is currently in Standards Mode. At this time, the width of the browser client area is document.documentElement.clientWidth

Post a copy below to accurately obtain the web page client Codes for area width and height, scroll bar width and height, scroll bar Left and Top

 1 if (document.compatMode == "BackCompat") 
 { 2   cWidth = document.body.clientWidth; 3   
 cHeight = document.body.clientHeight; 4   
 sWidth = document.body.scrollWidth; 5   sHeight = document.body.scrollHeight; 6   
 sLeft = document.body.scrollLeft; 7   sTop = document.body.scrollTop; 8 } 
 else { //document.compatMode == "CSS1Compat" 9   cWidth = document.documentElement.clientWidth;10   
 cHeight = document.documentElement.clientHeight;11   sWidth = document.documentElement.scrollWidth;12   
 sHeight = document.documentElement.scrollHeight;13   
 sLeft = document.documentElement.scrollLeft == 0 ? 
 document.body.scrollLeft : document.documentElement.scrollLeft;14   
 sTop = document.documentElement.scrollTop == 0 ? 
 document.body.scrollTop : document.documentElement.scrollTop;15 }

The above is the detailed content of Attributes in js: document.compatMode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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