window.innerWidth can't work on IE7. How to fix via JS and jQuery?

余生长醉 提交于 2019-12-19 11:50:34

问题


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

How to fix this issue via JS?

How to fix this issue via jQuery?

Thank you!


回答1:


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




回答2:


this would fix using a jquery $(window).innerWidth();



来源:https://stackoverflow.com/questions/9563627/window-innerwidth-cant-work-on-ie7-how-to-fix-via-js-and-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!