Document mode in the development of seemingly rarely used, the most common is to get the page when the width of the high, such as the document width is high, the visible area wide high.
IE's rendering of box models is very different in standards mode and quirks mode, and the interpretation of box models under standards mode is the same as other standard browsers, but in quirks mode it is very different. In the case of not declaring doctype, IE defaults to quirks mode. So for compatibility reasons, we may need to get the current document rendering method.
Document.compatmode comes in handy, and it has two possible return values: Backcompat and Css1compat.
Backcompat: Standard compatibility mode is off. Browser client area width is document.body.clientwidth;css1compat: Standard compatibility mode is turned on. Browser client area width is document.documentElement.clientWidth.
So write a code that accurately gets the width, height, scroll bar, left, and top of the page's client area:
The code is as follows:
if(Document.compatmode = = "Backcompat") {Cwidth=Document.body.clientWidth; Cheight=Document.body.clientHeight; Swidth=Document.body.scrollWidth; Sheight=Document.body.scrollHeight; Sleft=Document.body.scrollLeft; STop=Document.body.scrollTop;} Else{//Document.compatmode = = "Css1compat"Cwidth =Document.documentElement.clientWidth; Cheight=Document.documentElement.clientHeight; Swidth=Document.documentElement.scrollWidth; Sheight=Document.documentElement.scrollHeight; Sleft= Document.documentElement.scrollLeft = = 0?Document.body.scrollLeft:document.documentElement.scrollLeft; STop= Document.documentElement.scrollTop = = 0?Document.body.scrollTop:document.documentElement.scrollTop;}
JavaScript Document.compatmode Properties