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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:34:35  来源:igfitidea点击:

How to get live browser's screen resolution

javascriptcssajax

提问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.screencontains the current OS resolution. That is accessible via screen.heightand screen.width. Two other interesting values might be availHeightand availWidth(not 100% sure about the cross-browser availabilty there)

window.screen包含当前的操作系统分辨率。可以通过screen.height和访问screen.width。另外两个有趣的值可能是availHeightavailWidth(不是 100% 确定那里的跨浏览器可用性)

If you need to know the current browser-dimensions, that is stored on the windowobject itself. window.innerHeight, window.outerHeight, window.innerWidthand window.outerWidthare 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.innerWidthwindow.outerWidth是那里感兴趣的值。所述预先指定的值并反映浏览器的工作(客户端)区域,而前缀包含整个浏览器窗口区域。