0

In JavaScript, is it possible to detect whether or not a device has the ability to be rotated?

Note: I am not asking how to get the current orientation of the device.

Context: I have to show a "rotate your device" warning if a device is in landscape orientation. But since that is only relevant on devices that can actually be rotated to portrait (usually phones and tablets, but not laptops and desktops), I want to determine if the device can be rotated first. Currently, I check if the device is a mobile device using sniffer.js. But I am curious if there is a better way?

Ben
  • 15,938
  • 19
  • 92
  • 138
  • 1
    [This question](https://stackoverflow.com/questions/4917664/detect-viewport-orientation-if-orientation-is-portrait-display-alert-message-ad) looks like a good place to start, as does [this one](https://stackoverflow.com/questions/36650949/how-to-detect-device-orientation-with-javascript). I'm not sure if the Screen API has a way to detect if it *can* be rotated. Though, taking a step back, is this really the correct approach to the underlying problem? What is that underlying problem that is solved by rotating the screen, and only solved on mobile devices? – David May 05 '23 at 18:06
  • 1
    https://whatwebcando.today/device-position.html – Marc May 05 '23 at 18:10

0 Answers0