Created
September 25, 2025 21:43
-
-
Save erikusaj/3c7f5602eb4f68a17234c028bd3e2dae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Get User Agent | |
| const userAgent = navigator.userAgent; | |
| // Get Device DPI (devicePixelRatio) | |
| const dpi = window.devicePixelRatio || 1; | |
| // Get Screen Size in Pixels | |
| const screenWidth = window.screen.width; | |
| const screenHeight = window.screen.height; | |
| // Approximate size in inches (CSS pixels assumed to be 96 DPI) | |
| const approxWidthInches = screenWidth / (dpi * 96); | |
| const approxHeightInches = screenHeight / (dpi * 96); | |
| // Convert inches to centimeters (1 inch = 2.54 cm) | |
| const approxWidthCm = approxWidthInches * 2.54; | |
| const approxHeightCm = approxHeightInches * 2.54; | |
| // Output | |
| console.log("User Agent:", userAgent); | |
| console.log("Device DPI (Pixel Ratio):", dpi) | |
| console.log("Screen Size:"+screenWidth +" x " + screenHeight +" pixels"); | |
| console.log("Approx Physical Size: "+ approxWidthInches.toFixed(2) + " x "+ approxHeightInches.toFixed(2) +" inches"); | |
| console.log("Approx Physical Size: "+ approxWidthCm.toFixed(2) +" x "+ approxHeightCm.toFixed(2) + " cm"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment