简体   繁体   English

JavaScript:如何获得窗口宽度和高度?

[英]JavaScript : How to get the window width and height?

I want to get the window height and width including Address bar , status bar,etc... 我想得到窗口的高度和宽度,包括地址栏,状态栏等...

How can I get the window full height and width as shown in the picture below ? 如何使窗口的高度和宽度如下图所示?

在此输入图像描述

Note : I know about the window.innerHeight and window.innerWidth . 注意:我知道window.innerHeightwindow.innerWidth It does not suits for this scenario. 它不适合这种情况。 window.innerHeight is used to get the DOM height only. window.innerHeight仅用于获取DOM高度。 outerWidth also does not gives what I have want. outerWidth也没有给出我想要的东西。

Hope our stack users will give a good solution with cross browser compatibility. 希望我们的堆栈用户能够提供跨浏览器兼容性的良好解决方案。

use this if you want without scrollbars etc.. : 如果你想要没有滚动条等,请使用它。:

window.innerHeight; // for height

window.innerWidth; // for width

else in your case, if you want it full, use the below. 在你的情况下,如果你想要它,请使用下面的。

window.outerHeight; // for height

window.outerWidth; // for width

How about using jQuery Fiddle 如何使用jQuery 小提琴

$(window).width();

$(window).height();

Source jQuery Window Width jQuery窗口宽度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM