document.compatMode属性
2016-05-30 19:01
357 查看
document.compatMode是用来判断当前浏览器采用的渲染方式。
有两个模式:
BackCompat:标准兼容模式关闭,当document.compatMode等于BackCompat时,浏览器客户区宽度为document.body.clientWidth;
CSS1Compat:标准兼容模式开启,当document.compatMode等于CSS1Compat时浏览器客户区宽度为document.documentElement.clientWidth;
准确获取网页客户区的宽高、滚动条宽高、滚动条Left和Top的代码:
总结:
有两个模式:
BackCompat:标准兼容模式关闭,当document.compatMode等于BackCompat时,浏览器客户区宽度为document.body.clientWidth;
CSS1Compat:标准兼容模式开启,当document.compatMode等于CSS1Compat时浏览器客户区宽度为document.documentElement.clientWidth;
准确获取网页客户区的宽高、滚动条宽高、滚动条Left和Top的代码:
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; }
总结:
var pageWidth=window.innerWidth; var pageHeight=window.innerHeight; if(typeof pageWidth!='number'){ if(document.compatMode=='CSS1Compat'){ pageWidth=document.documentElement.clientWidth; pageHeight=document.documentElement.clientHeight; }else{ pageWidth=document.body.clientWidth; pageHeight=document.body.clientHeight; } }
相关文章推荐
- CodeForces 638 A Home Numbers(数学,水题)
- Web页面请求的历程(三)
- linux 连接windows 共享文件夹
- Git 与 Github 的使用 —— 下载单个图像或单个文件夹
- File_operations结构体
- 计算纬度、经度距离,返回公里(千米)数
- FlashBuilder 新建项目时提示 java.lang.nullpointerexception
- Prepared statement peculiarities (P_S to the rescue)
- Crontab定时任务配置
- jQuery基础
- 关于自动化测试
- (转载)git常用命令
- 使用Markdown写文档
- jquery 插件 validate 的常用方法
- java对数组、List、Map排序及常用方法
- 数理统计与参数估计
- 【Bugly干货分享】“HTTPS”安全在哪里?
- ct04特性批量导入、特性长文本批量导入(BAPI_CHARACT_CREATE、BAPI_CHARACT_CHANGE、BAPI_CHARACT_ADDLONGTEXT)
- 微信浏览器如何禁止iPhone手机上下滑动网页
- iOS 多线程篇6—线程的状态