document.compatMode介绍

document.compatMode 检查当前的文档渲染模式

返回值:BackCompat和CSS1Compat;

IE对两种模式渲染差别很大;

BackCompat: Standards-compliant mode is not switched on. (Quirks Mode) //默认模式

CSS1Compat: Standards-compliant mode is switched on. (Standards Mode) //标准模式

例子:

alert(document.body.clientWidth + '-' + document.documentElement.clientWidth + '-' + document.compatMode);

document.body.clientWidth ==> BODY对象宽度
document.body.clientHeight ==> BODY对象高度
document.documentElement.clientWidth ==> 可见区域宽度(Quirks Mode不兼容)
document.documentElement.clientHeight ==> 可见区域高度Quirks Mode不兼容

IE标准模式下 clientWidth 和 scrollWidth值相同;

原文地址:https://www.cnblogs.com/kk073000/p/2844391.html