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 Code that accurately obtains the width and height of the client, the scroll bar width and height, and the left and top of the page is written: copy Code 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. scrolll EFT;
stop = document. body. scrolltop;
}< br> 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;
}