Device Orientation API returns different values for desktop browsers

我们两清 提交于 2019-12-18 06:59:38

问题


Using the Device Orientation API demo on desktop Firefox 44 and Chrome Version 47.0.2526.80 m return different results for the coordinates.

Firefox returns null and Chrome 0. So far so good.

With this piece of code I am trying to check deviceorientation data.

So first I check if the Device Orientation event is supported and both Firefox and Chrome say it is with the first alert firing.

if(window.DeviceOrientationEvent) {
  alert("Device Orientation Event is supported.");

  window.addEventListener('deviceorientation', function(event) {
    var alpha = event.alpha;
    var beta = event.beta;
    var gamma = event.gamma;

    // https://stackoverflow.com/a/27550756
    if(alpha === null && typeof alpha === "object")
      alert(alpha);
  }, false);
}

However only Chrome correctly returns the second alert as null whereas Firefox does not trigger the alert at all. But it should do so looking at the data results from the Device Orientation API demo.

I have also made sure to specifically check for null and not "", undefined, false, 0, or NaN as per How do I check for null values in JavaScript?

So how do I get Firefox to actually fire the second alert with the data of the deviceorientation ?

Related questions:

Device Orientation not working firefox

'deviceorientation' in Firefox?

Different gyroscope values in chrome mobile and safari mobile

Testing hardware support in Javascript for device orientation events of the iPhone 3GS

来源:https://stackoverflow.com/questions/35093857/device-orientation-api-returns-different-values-for-desktop-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!