【问题标题】:How to detect the page width and height in Javascript? [duplicate]如何检测 Javascript 中的页面宽度和高度? [复制]
【发布时间】:2014-03-17 11:37:27
【问题描述】:

我需要一些关于 html/javascript 中的小东西的帮助,我如何制作一个 javascript 代码来检测页面宽度和高度,当它小于我想要的时,只是弹出一个警报,告诉“按 Ctrl -”进行调整. (我知道怎么做消息,只需要检测页面大小的帮助)

谢谢!

【问题讨论】:

  • 不,我只是需要帮助。
  • 使用 CSS 媒体查询。

标签: javascript html


【解决方案1】:

JQuery 的快速代码 sn-p:

if ($(document).height() < minHeight || $(document).width() < minWidth) {
    // call popup
}

minHeightminWidth 是您应该定义的变量。

【讨论】:

    【解决方案2】:

    如果你想要 Ctrl - 意味着你想要浏览器的高度和宽度用于大屏幕 当您按 Ctrl 键时 - 之后按照此步骤操作(获取宽度、高度的简单方法)

    Press F12 - > Click on Console -> now right side under search option [in fire bug window] type window.innerWidth then select window.innerWidth and press run button which is exact under this window (bottom) and  check in console [bottom] browser print window.innerWidth. Do same for get window.innerHeight
    

    【讨论】:

      【解决方案3】:

      尝试以下解决方案来检测页面宽度和高度

      var pageWidth = document.documentElement.clientWidth,
          pageHeight = document.documentElement.clientHeight;
      alert('Page Width '+pageWidth);
      alert('Page Height '+pageHeight);
      

      Fiddle Demo

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多