0

I just need a boolean to say whether the device is a desktop or not because the design team has given us requirements to behave differently depending on if the webpage is run on a desktop or a tablet. We can assume tablets mean iOS and Android, and desktop is Linux, Windows, MacOS. A Surface Pro would count as desktop. We cannot make any assumptions based on the screen size. There are large tablets and small desktops.

More broadly, we are using Expo React-Native (managed) web target, if CSS cannot provide this information.

Karatekid430
  • 940
  • 11
  • 25
  • Are they really wanting to detect desktop or mobile, the distinction is pretty subjective, or are they wanting to detect certain capabilities and facilities, like whether the user is using a mouse? Even that sort of thing is woolly because users can switch. – A Haworth Jan 19 '22 at 04:27

1 Answers1

0

CSS itself cannot detect Surface Pro well, you should use JavaScript instead.

It's not difficult to detect the operating system, but for Surface Pro, it is actually a tablet, but you counted it as a desktop.

Here is a rough way to do so and also this, but the result is not guaranteed, since it's based on the User Agent string.

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • Surface Pro might have a tablet form, but it really is a desktop / laptop. It does not run a mobile OS and still has a keyboard, mouse cursor. – Karatekid430 Jan 19 '22 at 04:21
  • So if it is easy to detect the OS I am happy to use that to define mobile as Android || iOS. Do you know how I can get the OS as a string? – Karatekid430 Jan 19 '22 at 04:22
  • Check the links in my answer. You can also Google it. – Raptor Jan 19 '22 at 07:02