JavaScript document.compatmode compatibility _javascript tips

Source: Internet
Author: User
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;
}
Related Article

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.