How to get the real screen size(screen resolution) by using js(如何使用js获取实际屏幕大小(屏幕分辨率))
本文介绍了如何使用js获取实际屏幕大小(屏幕分辨率)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道是否存在以js表示的屏幕实际大小(屏幕分辨率)。
- 我知道
screen
接口,但它的结果不是我想要的。
screen;
// Screen {availWidth: 1680, availHeight: 973, width: 1680, height: 1050, colorDepth: 30, …}
screen.width;
// 1680
screen.height;
// 1050
我得到了width: 1680, height: 1050
;
实际上屏幕尺寸是2880 x 1800
;
我的屏幕截图
那么,任何人都可以帮助吗?
推荐答案
屏幕分辨率≠窗口宽度
更改屏幕dpi的大多数操作系统都会使用os dpi返回屏幕大小。例如,我的屏幕分辨率为1920x1080,而Windows默认dpi为125,因此js creen.width返回1600px
使用此选项:
function getResolution() {
const realWidth = window.screen.width * window.devicePixelRatio;
const realHeight = window.screen.height * window.devicePixelRatio;
console.log(`Your screen resolution is: ${realWidth} x ${realHeight}`);
}
// test
getResolution();
// Your screen resolution is: 3840 x 2160
这篇关于如何使用js获取实际屏幕大小(屏幕分辨率)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:如何使用js获取实际屏幕大小(屏幕分辨率)


基础教程推荐
猜你喜欢
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01