如何在Internet Explorer 8中获取innerWidth [英] How Do I Get innerWidth in Internet explorer 8

查看:155
本文介绍了如何在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.

这篇关于如何在Internet Explorer 8中获取innerWidth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆