如何在Internet Explorer 8中获取innerWidth

如何在Internet Explorer 8中获取innerWidth

问题描述:

在最近的所有浏览器中:

In all recent browser:

 window.innerWidth // 1920

在Internet Explorer 8中

In Internet explorer 8

 window.innerWidth // undefined

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

What is the best way to get this value in IE8?

IE9不支持IE8支持 innerWidth ,你可以这样做insteaad:

The innerWidth is supported by IE9 not IE8, you can do this insteaad:

var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

以上行将为您提供IE以及其他符合标准的浏览器的宽度。

The above line will get you the width from IE as well as other standard-compliant browsers.

如果使用jQuery, $(窗口).innerWidth()也会在所有浏览器中为您提供所需的结果。

If you use jQuery, $(window).innerWidth() will give you desired result in all browsers too.