The rendering of the box model in IE is very different from the standards mode and quirks mode, and the interpretation of the box model under Standards mode is the same as that of other standard browsers, but in quirks mode, there is a big difference. In the case of not declaring doctype, IE defaults to quirks mode. So for compatibility reasons, we might need to get the current document rendering mode.
Document.compatmode comes in handy, and it has two possible return values: Backcompat and Css1compat.
Backcompat: Standard compatibility mode shutdown. Browser client area width is document.body.clientwidth;css1compat: Standard compatibility mode is turned on. The browser client area width is document.documentElement.clientWidth.
So I wrote an exact code to get the width, scroll bar width, scroll bar left and top of the page client area:
Copy Code code as follows:
if (Document.compatmode = "Backcompat") {
Cwidth = document.body.client Width;
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;
}