【问题标题】:Determining the browser width with standalone code使用独立代码确定浏览器宽度
【发布时间】:2019-09-10 14:44:07
【问题描述】:

我从这个问题 (How to get document height and width without using jquery) 中得到了这个代码:

width = Math.max(
    document.documentElement.clientWidth,
    document.body.scrollWidth,
    document.documentElement.scrollWidth,
    document.body.offsetWidth,
    document.documentElement.offsetWidth
);

它有多可靠?它在 Opera 12 上似乎没有按预期工作 - 但现在已经相当老了。

除了那个浏览器,它似乎还可以。

【问题讨论】:

    标签: javascript


    【解决方案1】:

    document.documentElement.clientWidthwindow.innerWidth 应该适用于所有浏览器(您可以在此处测试https://ryanve.com/lab/dimensions/)。 Opera 12 已有 8 年历史,无法在 https://browserstack.com 上进行测试,因此我无法测试。

    仅供参考,如果您关心滚动条的宽度,请查看以下帖子:

    【讨论】:

      猜你喜欢
      • 2010-11-05
      • 2012-06-19
      • 2020-10-22
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 2015-03-17
      • 2011-09-21
      相关资源
      最近更新 更多