xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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 x 1050px

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

https://stackoverflow.com/questions/65462643/how-to-get-the-real-screen-sizescreen-resolution-by-using-js/65463713#65463713



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-12-29 11:14  xgqfrms  阅读(162)  评论(3编辑  收藏  举报