首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Internet explorer 8中获取innerWidth

如何在Internet explorer 8中获取innerWidth
EN

Stack Overflow用户
提问于 2012-02-23 17:19:38
回答 7查看 43.2K关注 0票数 60

在所有最新的浏览器中:

代码语言:javascript
复制
 window.innerWidth // 1920

在Internet explorer 8中

代码语言:javascript
复制
 window.innerWidth // undefined

在IE8中获取此值的最佳方法是什么?

EN

回答 7

Stack Overflow用户

发布于 2013-07-14 19:45:20

为了得到这个,我仍然使用:

代码语言:javascript
复制
window.innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
window.innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

但要模仿真正的dom-getter,请看下面这个:https://stackoverflow.com/a/18136089/1250044

票数 5
EN

Stack Overflow用户

发布于 2013-02-14 19:34:05

供ie8使用

代码语言:javascript
复制
document.documentElement.clientWidth
票数 4
EN

Stack Overflow用户

发布于 2013-12-19 06:19:49

我知道innerWidth可能不太一样,但getBoundingClientRect也可以用于类似的功能:

代码语言:javascript
复制
elem = document.documentElement.getBoundingClientRect();
width = elem.getBoundingClientRect().right - elem.getBoundingClientRect().left;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9410088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档