Skip to content
Advertisement

How to get current screen orientation in iOS Safari?

I am trying to get the current screen orientation of iOS however my function which work on chrome dev tool emulator and desktop but it doesn’t work on iOS.

Here is my function:

JavaScript

and here is how my program rougthly do to detect the screen orientation change and to use the function:

JavaScript

I tried using window.screen.height and window.screen.width however it didn’t worked. Here is the function:

JavaScript

I launch the iOS safari debugger on a mac vm and I noticed that the window.screen value doesn’t changes when I turn the screen: thing i noticed

It made me wonder what are the different property I can use to detect the screen orientation on ios ?

Advertisement

Answer

If you want to do some CSS, you can use media queries.

https://developer.mozilla.org/en-US/docs/Web/CSS/@media/orientation

Basically you can use @media (orientation: landscape) {}

If you want it in JS, for other purposes, you can use:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement