JavaScript document. compatmode compatibility

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.