2

I have a website that needs to distinguish between mobile phones, tablets, and ordinary laptops. Normally I could use an asp.net function to tell, but the complication is that I want tablets to be treated as NOT being mobile devices. Any device with a screen diagonal greater than 7.5 inches would get the normal website, and any device with a screen dialog of less than this would get the mobile version of the site.

First I thought all I need to do is get the screen.width (I'm using JavaScript) and screen.height, apply the pythagorean theorem to get the length of the diagonal (in pixels) and then divide by pixels-per-inch. The issue is this: Is "pixels-per-inch" always 96 for every type of device? If not, I can't do this.

Thanks.

Gideon Isaac
  • 395
  • 4
  • 17
  • 4
    Do you know about CSS media queries? Are you planning to have two separate websites, one for regular/large devices and another for smaller devices, with each website being on its own domain? – Marc Audet Jun 13 '15 at 11:18
  • 1
    Related (duplicate? I didn't vote because if I did, it would close the question immediately and I'm not sure enough): http://stackoverflow.com/questions/21680629/getting-the-physical-screen-dimensions-dpi-pixel-density-in-chrome-on-androi – T.J. Crowder Jun 13 '15 at 11:20
  • It would be one website, but with a different home page, which has different links, based on whether I'm dealing with a small screen or not. – Gideon Isaac Jun 13 '15 at 17:25
  • @MarcAudet media queries can't tell you the physical dimensions of your screen – Michael May 07 '19 at 02:59

1 Answers1

2

How do I know how many physical inches a device screen has?

You can't.

Is "pixels-per-inch" always 96 for every type of device?

No, not remotely. Not only do you have the issue of Retina displays, but if I have a notebook computer with a screen resolution of 1280x768, if the screen is 15.1" it's going to have a lower PPI than if the screen is 10.1".

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875