【问题标题】:window.innerWidth can't work on IE7. How to fix via JS and jQuery?window.innerWidth 不能在 IE7 上运行。如何通过 JS 和 jQuery 修复?
【发布时间】:2012-03-22 17:55:06
【问题描述】:

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

如何通过 JS 解决这个问题?

如何通过 jQuery 解决这个问题?

谢谢!

【问题讨论】:

    标签: javascript internet-explorer dom internet-explorer-7


    【解决方案1】:

    网上有很多这样的例子。这是一个常见的问题。这是我在快速搜索中找到的内容

    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

    【讨论】:

    • 感谢您的回答!有 jQuery 解决方案吗?我用$(window).innerWidth(),但是不正确。
    • 据我所知,jQuery 不支持修复。 innerWidth() 对文档或窗口对象无效。您被告知对这些对象使用 .width(),但它不包括滚动条。你能做的最好的就是使用 jQuery 来检测浏览器,但你不应该这样做来修复对象。
    【解决方案2】:

    这将使用 jquery 修复 $(window).innerWidth();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      • 2016-04-02
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多