javascript 如何获取实时浏览器的屏幕分辨率
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8787781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get live browser's screen resolution
提问by udaya shakya
I want to get live screen resolution of web browser as user RESTORE DOWN OR MAXIMIZE without refreshing the page.
我想在用户还原或最大化而不刷新页面的情况下获得 Web 浏览器的实时屏幕分辨率。
回答by Karthik Rao
Are you using jQuery? If yes, then the code below should work
你在使用 jQuery 吗?如果是,那么下面的代码应该可以工作
$(window).resize(function(){
var windowWidth = $(window).width();
var windowHeight = $(window).height();
// windowWidth & windowHeight are automatically updated when the browser size is modified
});
回答by jAndy
Not entirely sure what you're after, but here are some suggestions.
不完全确定你在追求什么,但这里有一些建议。
window.screen
contains the current OS resolution. That is accessible via screen.height
and screen.width
. Two other interesting values might be availHeight
and availWidth
(not 100% sure about the cross-browser availabilty there)
window.screen
包含当前的操作系统分辨率。可以通过screen.height
和访问screen.width
。另外两个有趣的值可能是availHeight
和availWidth
(不是 100% 确定那里的跨浏览器可用性)
If you need to know the current browser-dimensions, that is stored on the window
object itself. window.innerHeight
, window.outerHeight
, window.innerWidth
and window.outerWidth
are the values of interest there. The innerprefixed values do reflect the working(client) area of the browser, whereas the outerprefixes contain the whole browser window area.
如果您需要知道当前的浏览器尺寸,则该尺寸存储在window
对象本身上。window.innerHeight
, window.outerHeight
,window.innerWidth
和window.outerWidth
是那里感兴趣的值。所述内预先指定的值并反映浏览器的工作(客户端)区域,而外前缀包含整个浏览器窗口区域。