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

RasMason
  • 1,968
  • 4
  • 32
  • 54
  • http://stackoverflow.com/questions/4917664/detect-viewport-orientation-if-orientation-is-portrait-display-alert-message-ad or http://stackoverflow.com/questions/15980680/can-i-determine-if-a-device-is-in-portrait-or-landscape-mode-using-jquery – epascarello Oct 15 '15 at 15:45
  • Thanks that first link did it – RasMason Oct 15 '15 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. – Rajshekar Reddy Apr 28 '18 at 03:16
  • @RajshekarReddy Question is over 3 years old, and did you see the comment above yours. LOL – epascarello Apr 28 '18 at 03: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.. – Rajshekar Reddy Apr 28 '18 at 03:30
  • Again, 3 years old... it was answered back than. And I am willing to bet another question has the answer you are talking about so find it and link that one too.... – epascarello Apr 28 '18 at 03:31
  • I did search but no luck. Anyways if I do find one i'll link it here... – Rajshekar Reddy Apr 28 '18 at 03:33

1 Answers1

-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");
    };

}
danleyb2
  • 988
  • 12
  • 18