1

I have seen very many questions asking how to detect if a device is mobile or not. Generally, they fall into 3 categories:

  1. Check the screen size/viewport
  2. Check the User Agent
  3. Use a library, such as Modernizr to work around browser capabilities.

After implementing what I could, I still run across a situation which I have never seen asked or addressed; On many mobile browsers, there is a "Request desktop site" (Chrome) "Desktop Mode" (Dolphin) or "Desktop View" (HTC Sense).

I have chosen strategy #1 above, which works unless the page is viewed in desktop mode. Implementing #2 has drawbacks (spoofing, uncatalogued agents, etc.).

Is there a reliable (cross browser) way to detect Desktop Mode on a mobile browser with Javascript? jQuery or other libraries would be okay, but it should be based upon feature detection, rather than an array of User Agents.

Community
  • 1
  • 1
Sablefoste
  • 3,680
  • 3
  • 35
  • 52
  • Most of the websites which give a desktop mode option have different urls for mobile and desktop. Your question requires more modularity i think. We can store user's desktop mode preference in a cookie and loads stylesheets based user's preference. – muratgozel Feb 11 '16 at 20:25
  • @muratgozel, thank you for the reply. Please note, I am not indicating a link within the website; rather, the mobile device can switch between "modes". This option is part of the browser app, not the web page. – Sablefoste Feb 11 '16 at 20:31

1 Answers1

-1

There is no way for a webpage to detect whether the device is actually a desktop computer or not. When "Request desktop site" is enabled, the phone acts just like a desktop does. One way to check this is to check the OS of the device. However, some phones use windows as their OS, so this won't work on windows phones.

Wais Kamal
  • 4,312
  • 2
  • 11
  • 26
  • Ok so obviously besides for Windows phones, how can this be done, and for Windows phones one can check the width – bluejayke Nov 29 '20 at 20:07