How to get the real screen size(screen resolution) by using js All In One
How to get the real screen size(screen resolution) by using js
获取用户屏幕的真实像素分辨率, 屏幕实际尺寸
window.devicePixelRatio
设备像素比
screen resolution
屏幕分辨率
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}
Your screen devicePixelRatio is: ${window.devicePixelRatio}
`);
}
// test
getResolution();
// Your screen resolution is: 3840 x 2160
retina screen bug ❌
视网膜屏幕错误
(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}
Your screen devicePixelRatio is: ${window.devicePixelRatio}
Your screen width is: ${window.screen.width}
Your screen height is: ${window.screen.height}
`);
})();
// Your screen resolution is: 3840 x 2160 (4K)
// Your screen resolution is: 3360 x 2100 ( 2.5K Retina Screen)
// Your screen resolution is: 1920 x 1080 ( 1080P / FHD)
Built-in Retina Display: 15.4-inch (2880 × 1800) ❌
DELL S2419HM Display: 23.5-inch (1920 × 1080) ✅
苹果视网膜屏幕默认缩放到 1680px
x 1050px
✅
Apple Retina Screen default scale to
1680px
x1050px
https://www.cnblogs.com/xgqfrms/p/14196834.html
https://www.cnblogs.com/xgqfrms/p/14205521.html
DPI
https://en.wikipedia.org/wiki/Dots_per_inch
屏幕分辨率
https://en.wikipedia.org/wiki/Display_resolution
https://en.wikipedia.org/wiki/Display_resolution#/media/File:Vector_Video_Standards8.svg
https://cn.screenresolution.org/
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14205521.html
未经授权禁止转载,违者必究!