document.compatMode
BackCompat: Standard compatibility mode is turned off. Browser width: document.body.clientWidth;
CSS1Compat: Standard compatibility mode is enabled. Browser width: document.documentElement.clientWidth.
The code copy is as follows:
var d = document,
dd = d.documentElement,
db = d.body,
dc = d.compatMode == 'CSS1Compat',
dx = dc ? dd: db;
cWidth = dx.clientWidth;
cHeight = dx.clientHeight;
sWidth = dx.scrollWidth;
sHeight = dx.scrollHeight;
sLeft = dx.scrollLeft;
sTop = dx.scrollTop;
In Standards mode:
The true width of the element = margin-left + border-left-width + padding-left + width + padding-right + border-right-width + margin-right;
In Quirks mode:
width is the actual width of the element, and the content width = width - (margin-left + margin-right + padding-left + padding-right + border-left-width + border-right-width)
How to determine how the current browser is parsing in js?
The document object has a property compatMode, which has two values:
BackCompat quirks mode
CSS1Compat corresponding to strict mode
Browser compatibility table
http://www.quirksmode.org/compatibility.html
历史原因:
When the early browsers Netscape 4 and Explorer 4 parsed css, they did not comply with the W3C standard. At this time, the parsing method was called quirks mode (weird mode), but as the W3C standard became more and more important Many browsers have begun to parse CSS according to W3C standard, and the model of parsing CSS according to W3C standard is called strict mode (strict mode)
firefly