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 area 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.
Therefore, you have written an example to accurately obtain the width and height of the client area of the webpage, the width and height of the scroll bar, and the left and top pages of the scroll bar.Code:
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;
}
// Get page height
Function pageheight (){
If ($. browser. MSIE ){
Return document. compatmode = "css1compat "? Document.doc umentelement. clientheight:
Document. Body. clientheight;
} Else {
Return self. innerheight;
}
};
// Get page width
Function pagewidth (){
If ($. browser. MSIE ){
Return document. compatmode = "css1compat "? Document.doc umentelement. clientwidth:
Document. Body. clientwidth;
} Else {
Return self. innerwidth;
}
};