I want to make a website, where an object which has for example a width of 100mm, is displayed with that width no matter what resolution the monitor or smartphone has.
For that reason I'm asking the user for his display dimensions to calculate the right ppi. However it doesn't work on all devices.
EDIT: This is the code I have so far:
var dpr = window.devicePixelRatio;
var inch = 25.4;
var pixelHeight = screen.height * dpr;
var pixelWidth = screen.width * dpr;
function calculatePpi(monitorDiagonal) {
return (Math.sqrt(Math.pow(pixelWidth, 2) + Math.pow(pixelHeight, 2))) / monitorDiagonal;
}
function mmToPx(mm) {
return (((mm / inch) * calculatePpi(monitorDiag)));
}