1

using

window.addEventListener('deviceorientation', handleOrientation); 

to listen for device orientation

I know I need to find the alpha of device (0 - 360) but don't know what range to use to find out if the phone is in landscape mode

7
  • stackoverflow.com/questions/4917664/… or stackoverflow.com/questions/15980680/… Commented Oct 15, 2015 at 15:45
  • Thanks that first link did it Commented Oct 15, 2015 at 16:27
  • 1
    @epascarello the question that is marked as duplicate is totally different from what the OP is asking here. I agree this is related to device orientation but the OP is specifically asking for deviceorientation event which none of the answers provide, but rather suggest other events. Those are not going to work for a PWA and only deviceorientation will work. So I request to reopen this. Commented Apr 28, 2018 at 3:16
  • @RajshekarReddy Question is over 3 years old, and did you see the comment above yours. LOL Commented Apr 28, 2018 at 3:28
  • @epascarello I understand that, Nothing offense. But now since PWA is in the market this event is required for the installed app to trigger orientation change to work. That is the reason I thought it would be a better option to reopen this.. Commented Apr 28, 2018 at 3:30

1 Answer 1

-1

You should check the alpha value from the event.

function handleOrientation (event) { if (event.alpha>89 && event.alpha<150) {//the device is landscape at 90 console.log("Device is landscape"); }; } 
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thanks this works but only if I tilt to the left
this is simply not true

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.