Understanding Document.compatmode Properties

Source: Internet
Author: User

This is the front-end of those things to see, I quote come over, convenient to look at later, query

Document.compatmode is used to determine the rendering method used by the current browser.

Official explanation:

Backcompat: Standard compatibility mode is off.
Css1compat: Standard compatibility mode is turned on.

When Document.compatmode equals Backcompat, the width of the browser client area is document.body.clientWidth;
When Document.compatmode equals Css1compat, the browser client area width is document.documentElement.clientWidth.

The height of the browser client area, the height of the scrollbar, the left of the scroll bar, the top of the scroll bar, and so on are all the above cases.

A code that accurately obtains the width, height, scroll bar, left, and top of the page's customer area:

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

(The above code is compatible with all currently popular browsers, including: IE, Firefox, Safari, Opera, Chrome)

Understanding Document.compatmode Properties

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.