Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect screen density using javascript on mobile devices?

I was wondering if it is possible to detect the screen density from a web page by using javascript and/or some sort of server checking based on http headers on PHP. My goal is to check if the user is accessing the site from a tablet, phone or computer to adjust some button sizes - imagens on a html5 canvas. Exact pixel values may lead to buttons too small or too big depending on the screen density...

like image 684
chokito76 Avatar asked Jun 26 '13 16:06

chokito76


2 Answers

I think most mobile browsers support window.devicePixelRatio.

like image 59
Kristoffer K Avatar answered Oct 17 '22 18:10

Kristoffer K


Most browsers support devicepixelratio with the exception of Internet Explorer versions 8 through 10. Thankfully as of January 12th 2016 all those versions have been officially deprecated and will no longer be supported by Microsoft with security updates or technical support.

like image 24
SavoryBytes Avatar answered Oct 17 '22 20:10

SavoryBytes