I understand that similar questions were asked before getting the dimensions of the device, etc., but there seems to be disagreement about the exact way to do this.
Suppose I have media queries (e.g. Twitter Bootstrap) using
Optional Small Devices Phones (<768px)
Small Pill Devices (≥768px)
Medium Devices Desktop Computers (≥992px)
Large Devices Desktop Computers (≥1200px)
Now, I would like to be able to use Javascript to get the same result. In other words, the pixel number of the css media request is not the actual points on the screen. those. I don’t need to get an exact answer, but I want to avoid getting out of one or two or three, because I get “screen points” and not css pixels.
I'm more interested in mobile devices - especially Android - than the desktop. Is screen.width reliable for this? Or jQuery(document).width() ?
(This is for a research project, and although I know that in principle it is impossible to detect a tablet compared to a phone, I would like to indicate the size of devices used by users. The user interface will not be dictated by the results.)
source share