The rendering of the box model by IE is very different in Standards Mode and Quirks Mode. The interpretation of the Box Model in Standards Mode is the same as that in other standard browsers, however, in the Quirks Mode, there is a big difference. In the case that Doctype is not declared, IE is the Quirks Mode by default. Therefore, for compatibility consideration, we may need to obtain the current document rendering method.
Document. compatMode comes in handy. It has two possible return values: BackCompat and CSS1Compat.
BackCompat: Disabled in standard compatibility mode. The client width of the browser is document. body. clientWidth; CSS1Compat: enabled in standard compatibility mode. The client width of the browser is document.doc umentElement. clientWidth.
The following code accurately obtains the width and height of the client area, the width and height of the scroll bar, and the Left and Top of the scroll bar:
Copy codeThe 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.doc umentElement. clientWidth;
CHeight = document.doc umentElement. clientHeight;
SWidth = document.doc umentElement. scrollWidth;
SHeight = document.doc umentElement. scrollHeight;
SLeft = document.doc umentElement. scrollLeft = 0? Document. body. scrollLeft: document.doc umentElement. scrollLeft;
STop = document.doc umentElement. scrollTop = 0? Document. body. scrollTop: document.doc umentElement. scrollTop;
}