window.innerWidth不能在IE7上工作。如何通过JS和jQuery修复? [英] window.innerWidth can't work on IE7. How to fix via JS and jQuery?

查看:108
本文介绍了window.innerWidth不能在IE7上工作。如何通过JS和jQuery修复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取浏览器窗口的宽度。如果存在,它应该包含滚动条的宽度。

I wanna get the width of browser window. It should contain the width of scroll bar if exists.

如何通过JS解决此问题?

How to fix this issue via JS?

通过jQuery解决这个问题?

How to fix this issue via jQuery?

谢谢!

推荐答案

网络上散布着许多例子。这是一个常见的问题。以下是我在快速搜索中找到的内容。

There are many examples of this scattered around the web. It's a common problem. Here's what I found in a quick search

var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
 winW = document.body.offsetWidth;
 winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth ) {
 winW = document.documentElement.offsetWidth;
 winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
 winW = window.innerWidth;
 winH = window.innerHeight;
}

http://www.javascripter.net/faq/browserw.htm

这篇关于window.innerWidth不能在IE7上工作。如何通过JS和jQuery修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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