//1英寸等于2.54 cm
let inch = 2.54;
//屏幕宽度(pixel)
let screenWidth = window.screen.width;
//屏幕高度(pixel)
let screenHeight = window.screen.height;
//dpi即一英寸长度的像素点个数(number)
let dpi = window.devicePixelRatio * 96;
//屏幕宽度(cm)
let width = (screenWidth / dpi) * inch;
//屏幕高度(cm)
let height = (screenHeight / dpi) * inch;
//对角线长度(cm) a²+b²=c² => c=√(a²+b²)
let diagonal = Math.sqrt(Math.pow(height, 2) + Math.pow(width, 2));
console.log("屏幕分辨率: " + screenWidth + " px x " + screenHeight+' px');
console.log("DPI: " + dpi);
console.log("宽 x 高(cm): " + width+' cm x '+height+' cm');
console.log("对角线长(cm): " + diagonal+' cm');